Hi All,
I hope you can help me. Forgive me for a little piece of C# code:
SpiCom = new SPI(new SPI.Configuration(Cpu.Pin.GPIO_NONE,
false, 0, 0, false, false, 1000, SPI.SPI_module.SPI1));
byte[] ReadBuffer = new byte[64];
// Create and fill write buffer
byte[] WriteBuffer = new byte[64];
for (byte c = 0; c < 64; c++) { WriteBuffer[c] = c; }
SpiCom.WriteRead(WriteBuffer, ReadBuffer);
This would fire 64 bytes over the SPI line and expects 64 bytes back from the slave. Now I have a Mongoose IMU that has a Arduino Pro mini Atmega 328 that allows me to change the firmware. I'd like to have it listen to SPI commands (bytes written) and answer by sending SPI bytes back. I expect one byte in return for every byte written.
The example above is ignoring the slave select pin and is running at 100Mhz.
I'm a complete aruino noob and this is the first time I ever worked on it, so please don't blaim me for any extremely stupid questions. This is what I figured out so far:
I should insert the SPI library:
#include <SPI.h>
I should initialize the library:
SPI.begin()
And now I'm lost XD
I know there is a SPI.transfer(byte) that writes a byte and reads a result, but that seems to be more like the master behaviour. As I client I would like it to read a byte and write a byte back later on. Is there any way of doing that or am I making another kind of mistake here?
Also, how should I set the clock speed and wait delay time of the SPI?
Thanks a lot for the time to read this and hopefully answer these questions