|
|
View previous topic :: View next topic |
Author |
Message |
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
UART problem - always received data is FF?! |
Posted: Tue Jan 15, 2013 2:45 am |
|
|
Hi, everyone! I made a simple pcb with 2 micros (18F2550 and 16F648A). I made simple programs for each of them - 18F2550 master and 16F648A slave:
Slave
Code: |
#include <16F648A.h>
#FUSES HS,NOWDT
#use delay(clock=20M)
#use rs232(baud=9600,parity=N,xmit=pin_B2,rcv=PIN_B1,stream=RS232,bits=8,errors)
void main()
{
delay_ms(1000);
while(1)
{
putc('0');
delay_ms(1000);
}
}
|
Master:
Code: |
#include <18F2550.h>
#fuses HS,NOWDT
#use delay(clock=20M)
#use rs232(baud=9600,parity=N,xmit=pin_C6,rcv=PIN_C7,stream=RS232,bits=8,errors)
char data;
void main()
{
delay_ms(1000);
while(1)
{
data=1;
if(kbhit())
{
data=getc();
delay_ms(1000);//break point here
}
}
}
|
I connected pin 18 (RX) of 18F2550 to pin 8 (TX) of 16F648A. I'm using PicKit 3 as debugger. The program is entering into the "if" statement, but the value of data is always 0xFF.
What am I doing wrong?
Thanks! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19546
|
|
Posted: Tue Jan 15, 2013 3:03 am |
|
|
OK. This suggests that one or the other chip is not clocking at the speed you think it is. Your 2550, won't be running at 20MHz. Reason is that you are not setting the CPUDIV divider, and this defaults to 4. So the 2550, is running at 5MHz, and is clocking the data in at 1/4 the rate it should be. Add the fuse CPUDIV1 to the ones selected for this chip, and see if things improve.
You can check this, by looking at the .lst file. With your fuses, you get:
Code: |
Configuration Fuses:
Word 1: CC3F PLL12 CPUDIV4 USBDIV HS FCMEN IESO
Word 2: 1E3E PUT BROWNOUT BORV21 VREGEN NOWDT WDT32768
Word 3: 8700 CCP2C1 PBADEN LPT1OSC MCLR
Word 4: 0081 STVREN NOLVP NOXINST NODEBUG
Word 5: C00F NOPROTECT NOCPB NOCPD
Word 6: E00F NOWRT NOWRTC NOWRTB NOWRTD
Word 7: 400F NOEBTR NOEBTRB
|
It's clocking it's LSb in six bit times after the falling edge, which with '0' sent (binary 00001100), just happens to be in the two 1's, so a 1 is clocked in, then the rest of the bits are all clocked after the byte has finished, when the line has returned to 'high', so 1's are then clocked in for everything else. Hence 0xFF.
Best Wishes |
|
|
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
|
Posted: Tue Jan 15, 2013 4:46 am |
|
|
That`s it! Thanks, again Ttelmah! |
|
|
|
|
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
|