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_write using other PORT ?

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



Joined: 29 Sep 2012
Posts: 8

View user's profile Send private message

SPI_write using other PORT ?
PostPosted: Sun Sep 30, 2012 11:01 pm     Reply with quote

I want to use SDO, CLK for my select Port, example : SDO=B2,CLK=B3.
I tried this code but it didn't work.
Code:

void spi_own_write(char aa){

output_low(PIN_B3);
output_bit(PIN_B2,bit_test(aa,7));
output_high(PIN_B3);
delay_cycles(10);

output_low(PIN_B3);
output_bit(PIN_B2,bit_test(aa,6));
output_high(PIN_B3);
delay_cycles(10);

output_low(PIN_B3);
output_bit(PIN_B2,bit_test(aa,5));
output_high(PIN_B3);
delay_cycles(10);

output_low(PIN_B3);
output_bit(PIN_B2,bit_test(aa,4));
output_high(PIN_B3);
delay_cycles(10);

output_low(PIN_B3);
output_bit(PIN_B2,bit_test(aa,3));
output_high(PIN_B3);
delay_cycles(10);

output_low(PIN_B3);
output_bit(PIN_B2,bit_test(aa,2));
output_high(PIN_B3);
delay_cycles(10);

output_low(PIN_B3);
output_bit(PIN_B2,bit_test(aa,1));
output_high(PIN_B3);
delay_cycles(10);

output_low(PIN_B3);
output_bit(PIN_B2,bit_test(aa,0));
output_high(PIN_B3);
delay_cycles(10);

}


Any help, plz
Ttelmah



Joined: 11 Mar 2010
Posts: 19393

View user's profile Send private message

PostPosted: Mon Oct 01, 2012 2:12 am     Reply with quote

You do realise that #USE SPI, and spi_xfer, will allow you to use _any_ pins?.
The code to do this is already written for you....

The code needed to go 'DIY', will depend on the SPI mode required. What you post will only work for a device that expects CPOL=1, and CPHA=1. Also you don't say your clock rate for the processor, or whether you are using standard_io, but if you are working at (say) 40MHz, then this will only pulse the clock line low for 400nSec.
If you look at the timings for the SPI hardware, you will see that in every case, the data bit is output _before_ the clock changes in any way.

Best Wishes
tidushuu



Joined: 29 Sep 2012
Posts: 8

View user's profile Send private message

PostPosted: Mon Oct 01, 2012 6:19 am     Reply with quote

thank for your reply and i made it ok .
But i have a questtion about speed ? what is better between SPI Hardware and SPI Software and can i use both in code ? ex : Setup_SPI for default port and #USE SPI for custom port ?
Thank again !
Ttelmah



Joined: 11 Mar 2010
Posts: 19393

View user's profile Send private message

PostPosted: Mon Oct 01, 2012 3:02 pm     Reply with quote

SPI hardware is _much_ faster.
Maximum speed depends on the processor family, but typically up to 1/4 the processor clock rate. Software perhaps 1/30th this 'best case'.
You can use #USE SPI for both if you want, and use streams, but using setup_spi will also work find for the hardware port, and seems still at times to be the fractionally more reliable route.

Best Wishes
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