Hello,
Environment:
- MCU: Seeeduino Xiao SAMD21
- RF: AS4432-SMD
- Arduino IDE v.2.3.4
- Board Manager: Arduino SAMD Boards (32bits ARM Cortext-M0+)
I have an idea to make a scanner based on Seeeduino Xiao SAMD21 and AS4432-SMD.
I made connections via the SPI protocol (4 pins), as far as I understand - I only need to configure the CS/SS pin.
Other pins are already configured by hardware.
I use Arduino IDE, my code was complex, but then I simplified it to the following code and as it turned out - it looks like the SPI protocol does not work for me.
How did I figure this out? - I have three AS4432-SMD boards and two MCUs - SAMD21 and ESP-32.
The second AS4432-SMD board - when reading registers 0x00 and 0x01 - returns 0xFC.
But - the first and third AS4432-SMD boards on both MCUs when reading registers 0x00 and 0x01 (in principle - when reading any register) - always return 0xFF.
Does anyone have an idea why this happens?
P.S. When I touched CLK pin by oscilloscope, I immediately have got following values from registers:
15:17:55.305 -> 0x00=[1000] 0x01=[110]
15:17:55.570 -> 0x00=[1000] 0x01=[110]
15:17:55.804 -> 0x00=[1000] 0x01=[110]
15:17:56.066 -> 0x00=[1000] 0x01=[110]
15:17:56.316 -> 0x00=[1000] 0x01=[110]
15:17:56.536 -> 0x00=[1000] 0x01=[110]
15:17:56.808 -> 0x00=[1000] 0x01=[110]
15:17:57.036 -> 0x00=[1000] 0x01=[110]
15:17:57.306 -> 0x00=[1000] 0x01=[110]
It look likes right values, BUT - every time after uploading the firmware, I have got 0xFF again and this continues until I touch the oscilloscope probe to the CLK pin on my XIAO SAMD21.
Source code:
#include <SPI.h>
// ----- Pin Definitions -----
#define SI4432_CS_PIN 3 // Chip Select (adjust if needed)
#define SI4432_IRQ_PIN 2 // Must be an interrupt-capable pin
//
// Setup and main loop
//
void setup() {
Serial.begin(115200);
while (!Serial); // Wait for Serial to initialize (if needed)
// Configure the chip select pin.
pinMode(SI4432_CS_PIN, OUTPUT);
digitalWrite(SI4432_CS_PIN, HIGH); // Idle state (CS inactive)
// Initialize SPI interface.
SPI.begin();
Serial.println("SI4432 initialization complete, now in RX mode.");
}
void loop() {
uint8_t devStatus = SI4432_readRegister(0x00);
uint8_t irqStatus1 = SI4432_readRegister(0x01);
Serial.print("devStatus=[");
Serial.print(devStatus, BIN);
Serial.print("] irqStatus1=[");
Serial.print(irqStatus1, BIN);
Serial.print("]");
delay(2000);
}
//
// Write to a SI4432 register via SPI.
// For writes, the SI4432 requires the register address with the MSB set.
void SI4432_writeRegister(uint8_t reg, uint8_t value) {
SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));
digitalWrite(SI4432_CS_PIN, LOW);
SPI.transfer(reg | 0x80); // MSB high indicates write operation
SPI.transfer(value);
digitalWrite(SI4432_CS_PIN, HIGH);
SPI.endTransaction();
}
//
// Read from a SI4432 register via SPI.
// For reads, the register address is sent with the MSB cleared.
uint8_t SI4432_readRegister(uint8_t reg) {
SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));
digitalWrite(SI4432_CS_PIN, LOW);
SPI.transfer(reg & 0x7F);
uint8_t value = SPI.transfer(0x00);
digitalWrite(SI4432_CS_PIN, HIGH);
SPI.endTransaction();
return value;
}
Regards,
Yevgen