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

SPI bus transmit buffering?

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



Joined: 20 Nov 2009
Posts: 13

View user's profile Send private message

SPI bus transmit buffering?
PostPosted: Sat Jun 29, 2013 9:54 am     Reply with quote

We are using SPI slave mode on a PIC18F46K22 to exchange messages with and PXA270 board. Receiving on the PIC is not a problem as the shift register is copied to SSP1BUF on receipt and I have 8 clocks to read it. When transmitting, the documentation says that the transmitted byte is copied to the shift register simultaneously with the write to SSP1BUF--meaning there is no buffering. As a result, since the PXA270 sends a continuous clock while receiving, I have only one clock (maybe) to load the next character after the previous byte is transmitted. I can't believe that this is how it is supposed to work? What I am seeing is a WCOL collision flag getting set after the first byte is sent.

Hopefully, someone out there has found a way to make this work.
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Sat Jun 29, 2013 12:33 pm     Reply with quote

That is the way SPI works. You have to pre-load the next byte. This is what is sent on the next transaction.
You load the SSPBUF, and this is transferred to the physical shift register on the _next_ clock from the master. If a master is expecting a reply, it has to allow enough time for this load to take place.
The code on your master would have to be changed to allow enough time for this to happen. The only devices that would support continuous 'unbroken' clocks would be ones using a double buffered RAM array, implemented in something like a FPGA. If you can't change the master code, then you'd have to add hardware buffering like this....

Best Wishes
dbaltz



Joined: 20 Nov 2009
Posts: 13

View user's profile Send private message

PostPosted: Sat Jun 29, 2013 4:24 pm     Reply with quote

That is really unfortunate (and inefficient) that the Master must send and receive a byte at a time. The overhead of the WriteFile and ReadFile is quite high. It would seem more useful if Microchip had buffered both the transmit and receive. I guess I know what to do now to make it work though. Thanks for the clarification.
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Sun Jun 30, 2013 3:14 am     Reply with quote

This is not only Microchip. 90+% of simpler microprocessors, do not double buffer the returned data in a slave transmit. The few that do, are a couple of later Motorola chips, some Texas chips, and faster chips like the PIC32.
The PIC32 does double buffer, and remember that chips supporting DMA, can auto load the byte for you (this is what most processors do). So most PIC24's for example, and few more exotic PIC18's.
Remember that the basic 'PIC', is a device with very limited RAM, so the idea of doing more than a few bytes in a transfer is not really handled, and a small amount like this can be handled by sitting polling the flag and loading immediately.

Best Wishes
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Jun 30, 2013 3:33 am     Reply with quote

Many of the PIC24 chips have a selectable 1- or 8-level FIFO on SPI.
dbaltz



Joined: 20 Nov 2009
Posts: 13

View user's profile Send private message

PostPosted: Mon Jul 01, 2013 8:40 am     Reply with quote

I'll probably use the PIC UART on future revs. It sounds like it will be faster and a lot easier.
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