Hi,
I am a pure VLSI design guy, and accidentally in arduino development area. So please pardon my illiteracy this this field.
I am currently using the following sequence to send data towards a SPI slave :
SPI.beginTransaction(settingsA);
digitalWrite (slaveSelect, HIGH); // This high is local hardware requirements
receivedData = SPI.transfer16(a);
Serial.print(receivedData, HEX);
digitalWrite(slaveSelect, LOW);
SPI.endTransaction();
In this sequence, I am sending data of length 16. However, I am suppose to send a commands ranging from length equal to 1 to 34 (different testing needs of VLSI hardware).
The straightforward question is, is it possible with current SPI library support in Arduino?
If not, then please guide what steps should be taken for the implementation of this functionality?
You didn't mention a specific board, so I'm going to assume an Arduino UNO.
AFAIK, the SPI hardware of the ATmega328P and similar chips only supports transmission of 8-bit bytes. SPI.transfer16 is implemented as two 8-bit transfers.
Some more advanced ARM boards have more advanced SPI hardware, but you'll have to consult the relevant datasheet, as these more advanced features are not likely to be supported by the standard SPI library.
Do you really need those specific lengths of messages? I'd simply pad them with zeros so they're multiples of 8 bits. If the device you're talking to has a 34-bit shift register as input, for instance, padding it with 6 bits at the beginning of the message shouldn't be an issue.
If that's not possible, the best option is to bit-bang an SPI interface in software, shouldn't be too hard for an SPI master.
Pieter
PieterP:
You didn't mention a specific board, so I'm going to assume an Arduino UNO.
AFAIK, the SPI hardware of the ATmega328P and similar chips only supports transmission of 8-bit bytes. SPI.transfer16 is implemented as two 8-bit transfers.
Some more advanced ARM boards have more advanced SPI hardware, but you'll have to consult the relevant datasheet, as these more advanced features are not likely to be supported by the standard SPI library.
Do you really need those specific lengths of messages? I'd simply pad them with zeros so they're multiples of 8 bits. If the device you're talking to has a 34-bit shift register as input, for instance, padding it with 6 bits at the beginning of the message shouldn't be an issue.
If that's not possible, the best option is to bit-bang an SPI interface in software, shouldn't be too hard for an SPI master.
Pieter
Thanks for the reply. Seems like I need to do the bit-banging. Actually the commands of different lengths are required for some internal hardware to switch to some other state. But for all communications, I have only one interface, and that is SPI. So seems like, first I need to disable SPI peripheral, perform some transaction, and switch it on back.
You could have an SPI_send function that looks like this
void SPI_send(uint8_t * sendData, uint8_t * receivedData, uint8_t length)
{
CHIP_SELECT_LOW;
for(uint8_t count=0; count<length; count++)
{
SPDR = sendData[count];
while(((SPSR & (1<<7)) == 0);
receivedData = SPDR;
}
CHIP_SELECT_HIGH;
}
SPDR/SPSR are register names and need to be renamed accordingly. That should give you flexibility to send up to 255 bytes in a single swoop.
tahirsengine:
So seems like, first I need to disable SPI peripheral, perform some transaction, and switch it on back.
Why?
hzrnbgy:
You could have an SPI_send function that looks like this
void SPI_send(uint8_t * sendData, uint8_t * receivedData, uint8_t length)
{
CHIP_SELECT_LOW;
for(uint8_t count=0; count<length; count++)
{
SPDR = sendData[count];
while(((SPSR & (1<<7)) == 0);
receivedData = SPDR;
}
CHIP_SELECT_HIGH;
}
SPDR/SPSR are register names and need to be renamed accordingly. That should give you flexibility to send up to 255 bytes in a single swoop.
That only works for multiples of 8 bits, which is not what OP is after.
ranging from length equal to 1 to 34
You meant to say this is 1 bit to 34 bits, not 1 byte to 34 bytes?