View previous topic :: View next topic |
Author |
Message |
Geps
Joined: 05 Jul 2010 Posts: 129
|
|
Posted: Mon Apr 11, 2011 9:09 am |
|
|
nahumof wrote: |
Code from Ttelmah
Code: |
void send_spi_byte(int8 ClockPin, int8 DataOutPin,int8 val_to_send) {
int8 count;
for (count=0;count<8;count++) {
output_bit(DataOutPin, shift_left(&val_to_send,1,0));
output_high(ClockPin);
output_low(ClockPin);
}
}
int8 get_spi_byte(int8 ClockPin, int8 DataInPin) {
int8 count;
int8 val;
for (count=0;count<8;count++) {
output_high(ClockPin);
shift_left(&val,1,input(DataInPin));
output_low(ClockPin);
}
return(val);
} |
I could use #use_spi as pic slave?
tks  |
I posted that code and Ttelmah pointed out when I did:
Quote: | Beware:
Pin definitions need to be an int16, for a PIC18. int8 definition, will only work for a PIC12/16.
Best Wishes |
|
|
 |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Apr 11, 2011 10:45 am |
|
|
Geps wrote: | I posted that code and Ttelmah pointed out when I did:
Quote: | Beware:
Pin definitions need to be an int16, for a PIC18. int8 definition, will only work for a PIC12/16.
Best Wishes |
| Thanks for explaining the error in the posted code, but you are missing the point that Nahumof is looking for a software SPI slave routine. Your code is for a SPI master.
Lets try to stay on topic. |
|
 |
nahumof
Joined: 09 Apr 2011 Posts: 15
|
|
Posted: Tue Apr 12, 2011 4:02 pm |
|
|
tks ckielstra
i will try to use uart or rebuild the hardware... i was using spi because i got 6 devices 1 pic master 2 slaves and 3 devices slaves spi.
master
1 master 18f4550 USB
slave
1 slave 16f876a is just for control a glcd display
1 slave 16f876a is for control a pid on a electro estimulator
devices
1 device adc for control touch
1 device adc amplifier input
1 device micro sd for recording
i thought it will be more easy to handle a single bus for all devices
 |
|
 |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Apr 14, 2011 7:06 am |
|
|
nahumof wrote: | 1 device micro sd for recording | A design hint here, to protect you from making the design error we made:
Writing to the SD card is always done in blocks of 512 bytes, this will take some time. So, if you have time critical processes running on the other SPI devices you might be better of to add an extra SPI bus for the fast devices. In the master it is easy to add a software SPI master routine. |
|
 |
|