Hello everyone,
I have a question regarding SPI. I'm currently working on a custom microscope project where I need to adjust a mirror (MR-E-2 from Optotune, find the manual here or look for it on the homepage of Optotune) via the SPI interface using an Arduino Uno board. So far, I was not able to control the mirror.
I wrote a very simple code for starters. Later in the project, the Arduino is supposed to receive mirror positions it will then transfer to the mirror. That is the reason I created a function called writeFloat().
My code is:
#include <SPI.h>
short writeCom = 0x0001;
void setup() {
Serial.begin(9600);
pinMode(SS, OUTPUT);
digitalWrite(SS, HIGH);
SPI.begin();
}
void writeFloat(short regAd1, short regAd2, float data1, float data2) {
SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE1));
digitalWrite(SS, LOW);
SPI.transfer(writeCom);
SPI.transfer(regAd1); // X register adress
SPI.transfer(regAd2); // Y register adress
SPI.transfer(data1); // data to write in regAd1
SPI.transfer(data2); // data to write in regAd2
digitalWrite(SS, HIGH);
SPI.endTransaction();
}
void loop() {
writeFloat(0x5000, 0x5100, 0x3d4ccccd, 0xbda3d70a);
delayMicroseconds(5);
}
The mirror needs to receive a signal frame consisting of 14 bytes:
2 bytes write/read command (here 0x0001 for write)
2 bytes register adress for x axis
2 bytes register adress for y axis
4 bytes of data to be written in the x register adress (here a float giving the current in x direction n amperes)
4 bytes of data to be written in the y register adress (here a float giving the current in y direction in amperes)
The values of the bytes in my code are taken from an example in the manual.
I connected the pins with the mirror following SPI - Arduino Reference.
I checked the wires connecting the Arduino and the mirror with an oscilloscope and what I see is that the clock signal goes up after every SPI.transfer(). But for the mirror to correctly process the command, it needs to receive the whole frame during one clock interval. My question now is: Is it possible to send 5 variables of different data types consisting of 14 bytes during one clock interval? Thanks in advance!
PS: This is my first time using Arduino, setting up an SPI connection and using this forum. I hope I gave you all the information you need.