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

Software SPI problems

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



Joined: 30 Apr 2007
Posts: 44

View user's profile Send private message

Software SPI problems
PostPosted: Fri Jul 13, 2007 3:15 am     Reply with quote

I am using the built-in SoftwareSPI lib. But it doesn't work correctly.
The only signal I see when I look on the pins with my oscilloscope is the clocksignal, the dataOut signal is just high..
The code I have written is like this:
Code:

#use Fast_io(B)
#USE SPI(MASTER, SAMPLE_RISE, MSB_FIRST, IDLE=1, DI=PIN_B4, DO=PIN_B6, CLK=PIN_B5, BAUD=102400, STREAM=SPI)

void main()
{
  set_tris_b(0x10);
  while(1)
  {
  SPI_Xfer(SPI,0b10101010);
  }
}

I have tried using diffrent pin like PIN_B3 but none work...
But if I do like this:
Code:

  while(1)
  {
  output_high(PIN_B2);
  SPI_Xfer(SPI,0b10101010);
  output_low(PIN_B2);
  SPI_Xfer(SPI,0b10101010);
  }

Then I get the signal on the B2 pin, but the DataOut pin is just high...
I'm going crazy over this! I can't see whats wrong.. Got any suggestions?

/Miniman
Miniman



Joined: 30 Apr 2007
Posts: 44

View user's profile Send private message

PostPosted: Fri Jul 13, 2007 4:25 am     Reply with quote

I think I found the problem!
if I include BITS=8 in the #use SPI it seems to work! I thought that was default..
But anyway, it seems to work now
/Miniman
Ttelmah
Guest







PostPosted: Fri Jul 13, 2007 4:44 am     Reply with quote

What compiler version?...
Have just compiled this with 4.038, and 4.042, and it is generating output on B5, and B6.
What load is on the B6 pin?.
The big problem though, is that the generated code, clocks out 32bits, not eight, so for the first 24 clocks, no output is generated on b6. Adding 'bits=8' to the declaration, solves this...

Best Wishes
Ttelmah
Guest







PostPosted: Fri Jul 13, 2007 4:45 am     Reply with quote

I see you found it while I was typing!. Smile

Best Wishes
Miniman



Joined: 30 Apr 2007
Posts: 44

View user's profile Send private message

PostPosted: Fri Jul 13, 2007 5:43 am     Reply with quote

Yes, I did. But thank you anyway! Very Happy
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