Hi everyone,
I am trying to use my Feather M0 to interface with this RF mixer [RF2051 (https://www.mouser.com/datasheet/2/412/f2051_data_sheet-1398223.pdf).
The documentation states that the registers on the device are programmed using a 3-wire serial bus. The wires are ENX, SCLK, and SDATA.
The question is what communication protocol would I use? How would I create a read and write function to communicate with the device? Would I use I2C or SPI? I assumed SPI so I tied the MISO and MOSI lines with a 3.3k resistor and connected ENX to one of the digital pins.
I tried writing a read and write function, but it didn't work. Is it because of a timing violation? Or is my code wrong?
I appreciate any advice or guidance!
#include <SPI.h>
#include "RF2051_REGS.h"
#define RESETB 14
#define CS_ENX 15
#define MODE 16
#define ENBL 19
void setup() {
while(!Serial){
delay(10);
}
Serial.begin(115200);
pinMode(RESETB, OUTPUT); // RESETB is active low
digitalWrite(RESETB, HIGH);
pinMode(CS_ENX, OUTPUT); // Initialize CS_ENX
digitalWrite(CS_ENX, HIGH);
SPI.begin();
SPI.setDataMode(SPI_MODE0)
}
void loop() {
Serial.println(spiRead(REG_CHIPREV), HEX); // REG_CHIPREV with address 0x19 should read 0x03
delay(1000);
}
uint16_t spiRead(uint8_t regAddress)
{
uint16_t regData;
digitalWrite(CS_ENX, LOW);
regData = SPI.transfer16(regAddress | (1 << 7));
digitalWrite(CS_ENX, HIGH);
return regData;
}
void spiWrite(uint8_t regAddress, uint16_t regData)
{
digitalWrite(CS_ENX, LOW);
SPI.transfer(regAddress);
SPI.transfer(regData);
digitalWrite(CS_ENX, HIGH);
}