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 Problem

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



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

SPI Problem
PostPosted: Tue Apr 25, 2006 9:14 am     Reply with quote

I am writing some values to registers on an MCP23S17 SPI port expander and for some reason the SPI comms are causing a problem.

If I write 0b01010101, when I read the value back I get 0b10101010.
When I write 0b00001111, when I read the value back I get 0b10001111.
When I write 0b11110000, when I read the value back I get 0b11111000.


Here's my SPI setup:

Code:
setup_spi(SPI_MASTER | SPI_H_TO_L | SPI_CLK_DIV_64);


Any ideas?

Thanks


UPDATE:

It appears it's a spi_read problem because the ports are set correctly. It's just when I read back the value I get the wrong info.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Apr 25, 2006 10:57 am     Reply with quote

Try using CharlieU's method of defining the SPI modes, as shown
in this post:
http://www.ccsinfo.com/forum/viewtopic.php?t=26662&start=4
Instead of using "SPI_H_TO_L", use his "SPI_MODE_0_0" constant
in setup_spi().
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

PostPosted: Tue Apr 25, 2006 11:12 am     Reply with quote

PCM,

I remember seeing that post previously. I didn't put two and two together.

It seems to have solved the problem.

Thanks!

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