I am trying to drive the ST25RU3993 Eval board using SPI, with my Arduino Due (both devices run on 3.3V) to prototype a quick project. I use the oscilloscope and it seems my spi outputs (sclk, mosi, chipselect, enable) is working. However my ST25 board is not responding at all.
#include <SPI.h>
////////////////////////////////////////////
//set up pins for arudino due
//MOSI:ICSP-4
//MISO:ICSP-1
//SCK:ICSP-3
//NCS:52
//EN:2
//
///////////////////////////////////////////////
// Set up chip-select pin as NCS and enable pin as EN
const int NCS = 52;
const int EN = 2;
//SPI setting
SPISettings settingsA(2000000, LSBFIRST, SPI_MODE1);
void setup() {
pinMode (NCS, OUTPUT);
pinMode(EN, OUTPUT);
digitalWrite(EN, HIGH);//set enable to high
SPI.begin();
// SPI.beginTransaction(settingsA); //I wrote to the following 2 main control registers, register description is at the data sheet
digitalWrite (NCS, LOW);
SPI.transfer(0b00000000); // write and register addressL: Device staus register
SPI.transfer(0b00000001); // value for this register: Turn RF-On
digitalWrite (NCS, HIGH);
digitalWrite (NCS, LOW);
SPI.transfer(0b00000001); // write and register addressL: Protocal Selection Register
SPI.transfer(0b00000000); // value for this register: Choose EPC Gen2
digitalWrite (NCS, HIGH);
// SPI.endTransaction();
}
void loop() {
//
for (int i = 0; i <= 255; i++) {
// SPI.beginTransaction(settingsA); //read from my RSSI_Display register
digitalWrite (NCS, LOW);
SPI.transfer(0b00101011);
digitalWrite (NCS, HIGH);
// SPI.endTransaction();
}
}
You need to re-enable begin/endTransaction to ensure you are using the right settings, which I believe to be 5000000 (max), MSBFIRST, SPI_MODE1.
If you are trying to read from the RSSI register then SPI.transfer(0b00101011) should be SPI.transfer(0b01101011) .
I would also consider powering the eval board over the USB port, at least until you get things working.
powering with USB port indeed turned the RFID board on, at least the PLL is running (PLL light was on the board)
and so I put the rate up to 5M, but I still don't get to read anything useful. Here is my modified version
#include <SPI.h>
////////////////////////////////////////////
//set up pins for arudino due
//MOSI:ICSP-4
//MISO:ICSP-1
//SCK:ICSP-3
//NCS:52
//en:2
//
///////////////////////////////////////////////
const int NCS = 52;
// set up the speed, data order and data mode
SPISettings settingsA(5000000, MSBFIRST, SPI_MODE1);
void setup() {
pinMode (NCS, OUTPUT);
pinMode(2, OUTPUT);
digitalWrite(2, HIGH);
Serial.begin(9600);
runonce(); // wirte my register only once
}
void runonce() {
SPI.begin();
SPI.beginTransaction(settingsA); //I wrote to the following 2 main control registers, register description is at the data sheet
digitalWrite (NCS, LOW);
SPI.transfer(0b00000000); // write and register addressL: Device staus register
SPI.transfer(0b00000001); // value for this register: Turn RF-On
digitalWrite (NCS, HIGH);
digitalWrite (NCS, LOW);
SPI.transfer(0b00000001); // write and register addressL: Protocal Selection Register
SPI.transfer(0b00000000); // value for this register: Choose EPC Gen2
digitalWrite (NCS, HIGH);
SPI.endTransaction();
Serial.print("written");
}
int8_t Q ;
void loop() {
for (int i = 0; i <= 5000; i++) {
digitalWrite (NCS, LOW);
Q = SPI.transfer(0b01101011);
digitalWrite (NCS, HIGH);
}
Serial.print(Q); // see it at serial monitor
}
like before checking with oscilloscope, the MOSI and SCLK looks good. MISO when probed gave square wave like signal but with only 100mV amplitude.
the serial monitor keeps outputting 75 with or without any tag presented or not.
I also put in a few other register addresses to read, getting back the same serial reading.
this board is getting quite confusing to me as why wouldn't it work..... :o
that was indeed the way i probe. btw when using the demo gui (which the eval board is successfully reading tags) all the led lights are quite bright while i my case it was dimmed. not sure i even turned the IC on or not ( EN is providing 3.3 V and it is also powered through USB)
That is odd with the LEDs. If I understood the documentation right, you should have enough power to operate the board even with just the 3.3V, albeit at a lower power shorter range. But better to supply all the power to eliminate at this stage.
Looking at the eval board document it says "SPI mode 1 (4 MHz)", which contradicts what I previously read. Better wind that down a bit, maybe to your original 2MHz.
With just the CLK connected what does the output on the MOSI pin look like with the MOSI wire disconnected and probing on the eval board?
Pulling this out of my rear, but maybe try a 10k pull-up on MISO - though it really shouldn't be necessary.
EDIT:
Even more ridiculous, try holding down the MCU reset button on the eval board when testing. It is also connected to the SPI pins, so maybe could interfere? Reset may of course reset the RFID chip too though...
I would expect it to be the usual active low (so high when not in reset). The reset pin has nothing to do with SPI in particular, it is just passed through on the header to allow all attached hardware to be reset when the Arduino is reset.
fghsfghsrthgt:
so arduino does idle high on MOSI pins on all 4 SPI modes, while strange enough, the st electronics use idle low for MOSI when I probe it.....
The SPI modes have more to do with the SCK signal. I'm no SPI expert, but I don't think MOSI has a particular idle state, the state is only valid when clocked so the slaves will otherwise ignore both a high and low level. I think MISO should be high-impedance in idle to avoid conflicts with the other slaves.
i got to read the register successfully.
the problem was not the idle low/high.
for anyone who might find this useful
so arduino spi has 1us delay for consecutive byte sending, during this time the sclk is put back to idle. that translates into: arduino spi can only work on SLOW clock rate, anything faster than 1MHz is going to corrupt. I put my clock down to 100k and it works now.
fghsfghsrthgt:
for anyone who might find this useful
so arduino spi has 1us delay for consecutive byte sending, during this time the sclk is put back to idle. that translates into: arduino spi can only work on SLOW clock rate, anything faster than 1MHz is going to corrupt. I put my clock down to 100k and it works now.
Glad you've made some progress, but I don't find your explanation satisfactory.
A 1us "idle" clock isn't going to make any difference since SPI operates on clock transitions.
You also scoped out MOSI & SCK in post #2 and they looked good. The problem was a low amplitude signal on the MISO, which is driven by the slave, ie. the ST25RU3993. So, if anything, it would suggest that the ST25RU3993 can't handle the speed (which I doubt).
Anyway, I don't know the answer, but if you have it working to your satisfaction then I'm happy too.
you are right, its that the sensor chip take the first 8 bit and immediately as register address and then immediately gives output-- so this requires non stoppable clock for 16 bit operation ( 16 clock cycles).
what happens when we set the clock too fast (1 clock cyc < 1us) is that we will have 8 cycles of clock -- clock down -- 8 cycles of clock. for which we are not going to be able to read anything.
so when i turn the clock way down (1 clock cyc >1us) we will have 8 cycles of clock --comparably small delay of 1us -- 8 cycles of clock, which it successfully reads.
ps, the small amplitude i probed was the coupling from the mosi pin.