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 INT16 Read/Write Routine

 
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 INT16 Read/Write Routine
PostPosted: Wed Oct 17, 2007 7:35 pm     Reply with quote

In the never ending attempt to get a MAX3100 working. I thought I'd try a bit-bang SPI function and see if it helps at all.

Can anyone offer any suggestions on the following:

http://datasheets.maxim-ic.com/en/ds/MAX3100.pdf

I think I've got the proper edges sampled.

Code:

#byte   PORTC = 0x0F82
#byte   LATC  = 0x0F8B
#byte   LATF  = 0x0F8E
#bit LCL_CS_BIT  = LATF.3   // local MAX3100 chip select
#bit SPI_CLK_PIN = LATC.3   // SPI SCLK
#bit MOSI_PIN    = LATC.5   // SPI MOSI
#bit MISO_PIN    = PORTC.4  // SPI MISO

int16 SSPtransfer16(int16 data_out)
{
   int8 i;
   int16 data_in;
   
   SPI_CLK_PIN = 0;      // direct addressing
   LCL_CS_PIN = 0;
   delay_cycles(2);
   
   for(i=0;i<16;i++)
   {
      SPI_CLK_PIN = 1;
      //----------------------
      // shift data in
      data_in <<= 1;
      if(!MISO_PIN)            // read the MISO pin
         data_in &= ~1;         // bit = 0
      else                  
         data_in |= 1;         // bit = 1
      //----------------------
      // shift data out
      if(bit_test(data_out,15))
         MOSI_PIN = 1;
      else
         MOSI_PIN = 0;
      //----------------------
      SPI_CLK_PIN = 0;
      data_out <<= 1;
   
   }
   delay_cycles(2);
   LCL_CS_PIN = 1;
   return (data_in);
}
jecottrell



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

View user's profile Send private message

PostPosted: Wed Oct 17, 2007 11:45 pm     Reply with quote

Looks like everything is working except for this part:

Code:
      // shift data in
      data_in <<= 1;
      if(!MISO_PIN)            // read the MISO pin
         data_in &= ~1;         // bit = 0
      else                  
         data_in |= 1;         // bit = 1



The low byte appears to be correct, but the high byte is 0.

Any ideas?

Thanks,

John

EDIT:

I've checked the data by reading it into an array and printing it out, and the data at the pin is correct.
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