View previous topic :: View next topic |
Author |
Message |
jbrodr
Joined: 15 Jul 2013 Posts: 3
|
RS232 on CAN Bus development kit |
Posted: Mon Jul 15, 2013 5:06 am |
|
|
I'm trying to use the Node A serial port, but it hangs. This code demonstrates the problem:
Code: |
#include <18F4580.h>
#fuses HS, NOLVP,NOWDT, NOPROTECT
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) // This hangs
//#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_B6) // This works
void main(void) {
putc(0x31); // print "1"
delay_ms(100);
}
|
Note if I change the 'receive' pin it then works.
Am I doing something stupid here? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9244 Location: Greensville,Ontario
|
|
Posted: Mon Jul 15, 2013 5:23 am |
|
|
Ok, at first I didn't see what would cause the problem...then...thought of this..
Your main program, sends a '1',delays 100ms then goes to sleep.
Sleep, because CCS inserts it as the last line of code(hidden).You need to code as follows..
main(){
while(1){
putc(0x31);
delay_ms(100);
}//end of while
}//end of main
This sends 1,delay,1,delay...forever..
My idea is that the code that works is using a software UART and sends the '1' which you see.When using the hardware UART, the PIC goes to sleep before the UART transmits the data nad you can see the '1'
If I'm not right(it's early here,no coffee either!..) maybe the hardware pin is NOT connected to the outdie world? Best to check with ohmeter to be sure!
hth
jay |
|
|
jbrodr
Joined: 15 Jul 2013 Posts: 3
|
|
Posted: Mon Jul 15, 2013 6:15 am |
|
|
Thanks Jay for the quick response but your fix doesn't work. It hangs on the putc() and never gets past it. It's waiting for the UART to empty. The hardware is fine; it happens on three separate boards.
However, looking at the ROM code in the debugger, something strange is happening.
...
0060: MOVLW 31
0062: BRA 004
...
0004: BTFSS 00:0
0006: BRA 0004
0008: MOVWF FAD
In other words, it's looking at address 00 and waiting for bit 0 to change, instead of looking at TXIF in special function register PIR1.
Has the compiler gone crazy, or just me? (PCH version 4.109) |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9244 Location: Greensville,Ontario
|
|
Posted: Mon Jul 15, 2013 7:58 am |
|
|
ratz...nothing these dayze is ever simple !!
I'd try using a previous compiler version, maybe there's a 'bug' in your current one?
hth
jay |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9244 Location: Greensville,Ontario
|
|
Posted: Mon Jul 15, 2013 8:06 am |
|
|
Ok...now on second pot of coffee!!
Compiled under PCH4v110
From the listing...
.................... #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) // This hangs
*
0004: BTFSS F9E.4
0006: BRA 0004
0008: MOVWF FAD
000A: GOTO 0060 (RETURN)
..which seems right, pretty sure F9E is the UART,would have to check,but phone ringing !!
hth
jay |
|
|
jbrodr
Joined: 15 Jul 2013 Posts: 3
|
|
Posted: Mon Jul 15, 2013 8:49 am |
|
|
Yup, F9E is the PIR1, so it's looking at the right place.
I must get another compiler version and try again.
or have a go at good ol' assembler.
Enjoy your coffee!
Jim |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Mon Jul 15, 2013 9:33 am |
|
|
Hi,
I had a thought. What do you have connected to the Rx pin? If it's floating, the UART may be receiving 'spurious' characters, and overflowing. This will
hang the UART, and (possibly) cause your program to stop at the Putc() statement. To test this theory, add 'Errors' to your #use rs232 statement,
or add a 'pull-up' resistor to the PIC Rx input to ensure it's held in the 'idle' state....
This behavior is definitely different between the 'soft' and the 'hard' serial port implementations, so that is why I figured it was worth a mention....
John |
|
|
|