CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Pic16f690 not sending bytes
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








Pic16f690 not sending bytes
PostPosted: Wed Jul 16, 2008 10:24 am     Reply with quote

Hi

I have this problem.

My pic is receiving byte on pin RA0 (pin19), but is not forwarding them
on pin RB7 (euart's transmit pin10).

According to the multimeter pin RA0 is actually receiving data.

Here is the code:
Code:

#include <16F690.h>
#fuses NOWDT,HS,NOPUT,NOPROTECT
#use delay(clock=4000000) 
#use rs232(baud=1200,parity=N,xmit=PIN_B7,rcv=PIN_B5,bits=8)

void clockwait(void);

void main()
{
   unsigned char byt;   // Holds each byte received
   unsigned char t;     // Variable t declaration

   setup_counters(RTCC_INTERNAL,RTCC_DIV_1);

   while(1)         // Loop forever...
   {
      byt=0;         // Starting a new data frame

      clockwait();      // Ignore start bit
      for(t=0;t<8;t++)      // Grab eight bits of data...
      {
         clockwait();
            byt|=input(PIN_A0)<<t;
      }
      clockwait();         // Ignore parity bit
      clockwait();      // Ignore stop bit

      putc(byt);         // Send byte to the transmitter

   }            // ... rinse and repeat :)
}

void clockwait(void)
{
   // Waits for the next clock cycle...
      while(!input(PIN_A1));   // Wait for clock to go HI
      while(input(PIN_A1));   // Wait for clock to go LO
}


P.S I'm using ccs 4.074 and PCM

Regards
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 16, 2008 11:16 am     Reply with quote

Make a test program. Prove that your PIC can talk to the PC via RS-232.
With this program, if you type characters into a terminal window on your
PC, they will be transmitted to the PIC. The PIC will send them back to
the PC and you will see them in the terminal window. Make sure that
you have a MAX232-type chip between the PIC and the PC.
Code:
#include <16F690.h>
#fuses INTRC_IO, NOWDT, NOBROWNOUT, PUT, NOMCLR
#use delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_B7, rcv=PIN_B5, ERRORS)

//=============================
void main()
{
char c;

printf("Start \n\r");

while(1)
  {
   c = getc();
   putc(c);
  }

}
Guest








PostPosted: Wed Jul 16, 2008 11:37 am     Reply with quote

I'm not sure how to do that.

I'm sending data wireless from the pic, I have connected a simple transmitter from velleman to the pic and on the receiving end I have connected matching receiver to a usb module, since both pic and usb module use TTL voltage levels no MAX232 chip is needed.

This is why I'm measuring with multimeter if there are any bits coming out from pic's pin.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 16, 2008 12:42 pm     Reply with quote

Your real problem is that your wireless communications are not working.
I'm not sure, but I think you are trying to create a software UART with
a few delay statements and loops. Use the CCS software UART library
code instead. Use "streams" with fgetc() and fputc() to specify whether
you are using the software or hardware UART. See the CCS manual.
Guest








PostPosted: Wed Jul 16, 2008 12:51 pm     Reply with quote

Quote:
Your real problem is that your wireless communications are not working.


If that is the case, shouldn't the multimeter give some output ( I'm measuring ac current on output pin?


Quote:
I'm not sure, but I think you are trying to create a software UART


I thought that I was using hardware UART, if not maybe the problem is that I'm not using hardware UART??
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 16, 2008 1:09 pm     Reply with quote

I don't know what you are doing. I'm giving up.
Guest








PostPosted: Wed Jul 16, 2008 1:49 pm     Reply with quote

I have connected a PS/2 keyboard to the pic and I'm trying to send the bits through the transmitter ( and making a wireless keyboard), the code was originally found online some where, It was a bit unfinished but it should work now, since it's just forwarding bits,

If I've understood this correctly it relays heavily on pic's built in functions
hence the simple code, and since it's one simple function it shouldn't mater if it is software or hardware uart ( not that i exactly know the difference).

the code was published as a newbie tutorial, when i finished doing all the "Hello world" programs I started with this, and I can't get it to work.

Wink
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Wed Jul 16, 2008 2:01 pm     Reply with quote

You have to separate your wireless problems from your software problems.

1) First see if you can send known data out a wired serial port (Hello World). Use a MAX232 or similar into a real serial port.

2) See if you can read the keyboard and send the data out the wired serial port.

3) See if you can send "Hello World" through a wireless link.

4) Then put the working pieces together.
_________________
The search for better is endless. Instead simply find very good and get the job done.
Guest








PostPosted: Wed Jul 16, 2008 2:22 pm     Reply with quote

Quote:
1) First see if you can send known data out a wired serial port (Hello World). Use a MAX232 or similar into a real serial port.


I'm messauring ac on output pin with a mulltimeter, and it shows nothing, (the input pin is geting the bits)

so the problem right now is that the pic is receiving bits but not sending anything out of it's pin.

Question
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 16, 2008 2:59 pm     Reply with quote

Make a test program that only sends bytes from the PIC.
Don't do anything else. This will prove if you can send bytes
from the PIC. Example:

Code:
#include <16F690.h>
#fuses INTRC_IO, NOWDT, NOBROWNOUT, PUT, MCLR
#use delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_B7, rcv=PIN_B5, ERRORS)

//=============================
void main()
{

printf("Hello World");

while(1);
}
Ttelmah
Guest







PostPosted: Wed Jul 16, 2008 3:07 pm     Reply with quote

A multimeter, is not a suitable tool to measure serial data with. Unless you have something like a graphical meter, or one supporting high speed sampling, most could not tell serial data from stable voltages...
As PCM programmer says. The _first_thing is to prove what part of the software works, or doesn't. Generate a simple radio message, and send this. Prove the link works.
Unfortunately, you will need to buffer your data to send it at 1200bps over the radio. PS/2, runs at over 10KHz, and a single keystroke, can involve multiple characters.
There is also another problem. Many simpler radio links, will require a number of characters to be sent, before they start working. Effectively if something is not sent for a short while, a few 'dummy' characters have to be sent first to adjust the AGC in the receiver, before normal comms can begin. I'd not be surprised if you send a simple 'hello world' type message, with a pause between the messages, if you then find that one or more of the transmitted characters are lost off the front of the message.

Best Wishes
Guest








PostPosted: Thu Jul 17, 2008 4:51 pm     Reply with quote

PCM Programmer,

I tested pic's original firmware from microchip (it's flashing LED's back and forward) and the pic worked fine, although I don't think that the xmit pin is used with example firmware.
So I will test your program and get back here.

Ttelmah

Quote:
Unfortunately, you will need to buffer your data to send it at 1200bps over the radio. PS/2, runs at over 10KHz,


This I don't exactly know how to calculate, here are the specs from the supplier of the transmitter, looking at data rate I thought I was safe, this transmitter is also according to the tutorial.

"
no adjustments required
stable output
suitable for remote controls, telemetry, ...

modulation: ASK
circuit shape: SAW
date rate: 100kbps
peak output power: 10mW
power supply: 3 ~ 12Vdc
pin numbers:
1: GND
2: data in
3: Vcc
4: ANT

Rolling Eyes
languer



Joined: 09 Jan 2004
Posts: 144
Location: USA

View user's profile Send private message

PostPosted: Fri Jul 18, 2008 1:48 am     Reply with quote

Instead of trying to get everything working all at once with some code which was found somewhere in the web (i.e. you do not understand if it works or not), why not break it down into smaller programs as has been suggested.

First off, write a small program (again, as previously suggested) which continuously transmits something through the PIC EUSART. Until you can read it through the PC, don't bother to go any further.

Then, connect the PS/2 keyboard and transmit the key strokes from it to the PC.

Finally, include the wireless interface.

The following link provides good information about how a PS/2 keyboard works. Its output is not RS232 asynchronous communications, but rather a bidirectional synchronous serial protocol.
Ttelmah
Guest







PostPosted: Fri Jul 18, 2008 2:39 am     Reply with quote

Good advice.
Also, the _transmitter_ supports 100Kbps, so why are you talking to it at 1200bps?
It is this that makes it impossible to handle the PS/2 data in the time.

Best Wishes
Guest








PostPosted: Fri Jul 18, 2008 4:45 am     Reply with quote

languer,
I will follow your advice above and get back here,
thnx for the very usefull link.


Ttelmah
1200baud is chosen simply because it was stated in the tutorial, after doing some research I got the impression that this was a stable rate to use with ps/2 protocol. Personally I don't understand the logic in why it has to be so slow, maybe simlby because 1200bytes (roughly) is more than enough??

I also don't understand the relation between running att 1200baud and keyboard runing at 10khz you were talking about earlier.

Rolling Eyes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group