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 bug 5.114 / PIC18F45K42

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



Joined: 24 Jun 2004
Posts: 1909

View user's profile Send private message

SPI bug 5.114 / PIC18F45K42
PostPosted: Fri Mar 03, 2023 11:39 am     Reply with quote

Alerted CCS to this issue a couple of days ago. Today they confirmed it's a bug and I wouldn't be surprised to see it fixed in the next update.

I use the traditional (old) way of using SPI:
- setup_spi()
- use spi_write() and spi_read() thereafter.

I did not attempt to try the newer #use spi and spi_xfer() method.

The issue is that spi_read(0x00) always returned 0, even though I could see (via logic analyzer) that the IC was not clocking back 0. My workaround was to change the reads to be spi_write(0) followed by a read of the SPI1RXB register, which would contain the correct data.

CCS just confirmed that spi_read(0) immediately returns and fetches the contents of SPI1RXB before the SPI peripheral even starts generating the 8 clocks.
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Fri Mar 03, 2023 11:58 am     Reply with quote

Historically that is what spi_read _did_.
If you wanted to read a byte and clock it, the standard syntax was to use:

val=spi_write(0);

Which forces a clock and returns the data.

Now they changed to allow a value to be passed to spi_read as you are
doing, a while ago. It sounds as if the update was not handled correctly
on this chip/compiler version.
I must admit I'd still use the older syntax, and this has always worked
fine....

It'd be quite interesting to see when this syntax changed.
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