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 CCS Technical Support

RS232 on CAN Bus development kit

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jbrodr



Joined: 15 Jul 2013
Posts: 3

View user's profile Send private message

RS232 on CAN Bus development kit
PostPosted: Mon Jul 15, 2013 5:06 am     Reply with quote

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: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Jul 15, 2013 5:23 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jul 15, 2013 6:15 am     Reply with quote

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: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Jul 15, 2013 7:58 am     Reply with quote

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: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Jul 15, 2013 8:06 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jul 15, 2013 8:49 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jul 15, 2013 9:33 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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