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

spi_write: dont understand asm code thats generated

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



Joined: 19 Sep 2003
Posts: 8

View user's profile Send private message Send e-mail

spi_write: dont understand asm code thats generated
PostPosted: Wed Dec 12, 2007 12:54 pm     Reply with quote

I have been having lots of trouble with spi bus and a 18f4685 (CCS v4.064)
Occasionally the chip sends the wrong data down the spi bus (have checked with a bus analyser). At the moment I am sending 3 bytes
spi_cmd_add=0b00110111;
spi_high=0b11110000;
spi_low=0b00000000;
and then calling
spi_write(spi_cmd_add);
spi_write(spi_high);
spi_write(spi_low);
on the SPI bus line coming out of the PIC I occansionaly see
00110111 10000000 00000000
instead of the correct values. As this is driving a D/A (LTC2620) you can image the problems this is causing!

I thought I would look at the code that the Complier has created and this is whats there
Code:

   spi_write(spi_cmd_add);
03476:  MOVF   FC9,W
03478:  MOVFF  443,FC9
0347C:  RRCF   FC7,W
0347E:  BNC   347C
....................       spi_write(spi_high);
03480:  MOVF   FC9,W
03482:  MOVFF  46,FC9
03486:  RRCF   FC7,W
03488:  BNC   3486
....................       spi_write(spi_low);
0348A:  MOVF   FC9,W
0348C:  MOVFF  45,FC9
03490:  RRCF   FC7,W
03492:  BNC   3490


So I know that FC9 is the SSPBUF and the data is being moved into the buffer what I dont understand is why its doing a RRCF on the FC7 which is the SSPSTAT reg? I assume its doing a test on BF (buffer full status bit) to detect when the data has been transmitted but cant understand how?
I am sure there is a simple reason but cant see it at the moment! this probably wont help my main problem but least I will get to undertsand how the SPI works at a low level.....
cheers
mike
(cambridge UK)
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Dec 12, 2007 1:17 pm     Reply with quote

Rotate Right the LSB into CY flag. Then branch on CY flag.


Post your setup_spi() statement.
mbarrett



Joined: 19 Sep 2003
Posts: 8

View user's profile Send private message Send e-mail

PostPosted: Fri Dec 14, 2007 5:11 am     Reply with quote

Obvious! thanks.
BTW I have found my problem. The setup is
SPPCON1 00100010
SPPCON2 00000000
I am feeding a pulse (ttl) into RA4 which is the pin next to RA5 which is the notSS pin. If I stop the pulse on RA4 problem stops, start the pulse problem comes back again. If I take RA5 which I am not using, high then problem stops and everything works fine. RA5 is the notSS enable pin although (I think, not sure of anything any more..) I am in master mode so this pin should not have any affect on the SPI but it does. Unless there is some other bit that needs setting that I have missed?
regards
mike
Ttelmah
Guest







PostPosted: Fri Dec 14, 2007 6:57 am     Reply with quote

I'd be inclined to suspect you may have found a silicon bug. There have been a _lot_ in the past with most 18F chips and the MSSP. The 4685, does not have any listed (yet), but this can easily be because they have not been spotted so far... :-(
It is quite interesting to look at the logic diagram for this line, which shows it just gating the SDO line. More reading, says that it should only be enabled by the bit pattern 0100, in the bottom bits of SSPCON1, but...
Have you got this pin left open circuit, but setup as an input?. If so, then it is common for this type of interraction to occur. Unused pins, should always be programmed as outputs, or pulled to one rail. Sometimes parts of the circuit that are disabled, can still partially function, if a floating pin induces spikes slightly outside the supply range. This might be what you are seeing.

Best Wishes
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