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

Strange problem with RS232, SPI and booting linux

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



Joined: 04 Aug 2006
Posts: 98

View user's profile Send private message

Strange problem with RS232, SPI and booting linux
PostPosted: Thu Oct 29, 2009 4:17 pm     Reply with quote

Hi

I have a PC that connects over RS232 to a PIC. This PIC connects to another PIC with SPI.

Now, what happens seems really strange. I switch on the PC and PICs through a shared power supply, the PC boots linux, the PICs just wait for a 'request' from the PC RS232 (a single byte). Once linux has booted, I run my program and... the SPI comms between the two PICs doesn't work.

So, I switch everything off, disconnect the rs232 cable, and then reboot the system. I let linux completely boot. Once linux has booted I plug the rs232 cable back in, run the linux program and... everything works straight away!

Something is happening on either the TX, RX or GND lines of the rs232 between the PC and the PIC during boot that is stopping the PICs from doing what they are supposed to. TX and RX are going through a MAX232 by the way.

I'm positive it's not a code thing because no transmission would occur until the linux program is started.

So I'm wondering if anyone has any ideas about this? The thing to note is that the system works when i disconnect the rs232 cable during booting linux. Otherwise, it doesn't and I have to take the PIC out of its socket for a moment, and put it back in, effectively resetting it and then it works. I'm stumped.. :/

Any help appreciated.
Thanks!

ps. here are my fuses:
Code:

#fuses NOWDT, WDT128, HS, NOPROTECT, NOIESO, NOBROWNOUT, BORV20, PUT, NOCPD, NOSTVREN, NODEBUG, NOLVP, NOWRT, NOWRTD, NOEBTR, NOCPB, NOEBTRB, NOWRTC, NOWRTB, NOFCMEN, NOXINST, NOPBADEN, NOLPT1OSC, NOMCLR
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Oct 29, 2009 4:32 pm     Reply with quote

Can you prove that the Linux PC doesn't send anything to the PIC board ?

Do you have ERRORS in the #use rs232 statement ? If not, add it.
theteaman



Joined: 04 Aug 2006
Posts: 98

View user's profile Send private message

PostPosted: Thu Oct 29, 2009 5:26 pm     Reply with quote

PCM programmer wrote:
Can you prove that the Linux PC doesn't send anything to the PIC board ?

All the PC does is boot, although I suppose I cannot be sure without testing.
Quote:

Do you have ERRORS in the #use rs232 statement ? If not, add it.

No I don't have ERRORS in the rs232 statement.. I will give it a shot but isn't that only if the buffer is overrun?
andyfraser



Joined: 04 May 2004
Posts: 47
Location: UK

View user's profile Send private message

PostPosted: Thu Oct 29, 2009 5:30 pm     Reply with quote

I would put a scope on the TX line from the PC to see if during boot Linux sends data. It may be that Linux looks for a modem on the port by sending an AT command which might mess up your PIC code ?

Andy
www.sharpcontrols.net :: Free custom controls for .NET
theteaman



Joined: 04 Aug 2006
Posts: 98

View user's profile Send private message

PostPosted: Thu Oct 29, 2009 6:09 pm     Reply with quote

andyfraser wrote:
I would put a scope on the TX line from the PC to see if during boot Linux sends data. It may be that Linux looks for a modem on the port by sending an AT command which might mess up your PIC code ?

Andy
www.sharpcontrols.net :: Free custom controls for .NET

Interesting... I'll look in to this, thanks! Smile
SherpaDoug



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

View user's profile Send private message

PostPosted: Thu Oct 29, 2009 6:17 pm     Reply with quote

Could the PICs be getting power from the serial port, through the protection diodes on the PIC die, then to the VCC bus, before they get power from their own power supply. That might cause bad timing of the /RESET signal relative the the VCC seen by the PIC.

I had a product once that would go to sleep and shut off its own VCC, but could never wake up because the serial connection kept the VCC from going down properly and the PIC only went into some half-sleep mode.
_________________
The search for better is endless. Instead simply find very good and get the job done.
Guest








PostPosted: Fri Oct 30, 2009 9:52 am     Reply with quote

I have also seen issues where upon the PC initializing a serial port (especially a USB one) a bad character(s) gets sent - this can hang the first command that the PIC was waiting for. A simple solution is to have the PIC's wait for the entire boot cycle before actually setting the USART to receive.

This is not a problem because the PIC's can't do anything until the PC boots fully anyway.

You can hook a debug serial port on an unused pin and monitor any serial input into your PIC by spitting it out the debug port - to another PC - just to see what is going on during the boot.

Windows PC's sent AT commands on USB serial ports looking for Modems, which is annoying to the Nth degree.

HTH - Steve H.
theteaman



Joined: 04 Aug 2006
Posts: 98

View user's profile Send private message

PostPosted: Fri Oct 30, 2009 2:42 pm     Reply with quote

Thanks for the help guys. Turns out the problem WAS down to Linux sending bytes during the boot sequence. What I've done now is just make sure the pics don't start until they receive an "ID" which is working fine!
Placing a delay in the PIC as guest said was another solution however the problem with this method is that as I continually increase the speed of the Linux boot over time, the pics would need to be reprogrammed with shorter delays each time otherwise they would be waiting too long. Anyway, problem solved - thanks everyone!!
Guest








PostPosted: Tue Nov 03, 2009 7:09 pm     Reply with quote

Yup - been there, done that! Glad you fixed the problem and confirmed the fix here on the board. That helps everyone in the future....

I have had the same issue with USB to serial adapters on the PC - some adapters when plugged in will emit junk when they enumerate that can hang my receive routines - a delay fixes that too.

Steve H.
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