|
|
View previous topic :: View next topic |
Author |
Message |
tidushuu
Joined: 29 Sep 2012 Posts: 8
|
SPI_write using other PORT ? |
Posted: Sun Sep 30, 2012 11:01 pm |
|
|
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: 19496
|
|
Posted: Mon Oct 01, 2012 2:12 am |
|
|
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
|
|
Posted: Mon Oct 01, 2012 6:19 am |
|
|
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: 19496
|
|
Posted: Mon Oct 01, 2012 3:02 pm |
|
|
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 |
|
|
|
|
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
|