2024-12-12 12:24 PM
## SPI configuration ##
static SPI_Config getSPIConfig(void)
{
return {
.SPI_DeviceMode = DEVICE_MODE_MASTER,
.SPI_Mode = SPI_MODE_3,
.SPI_BaudRate = BR_DIV32,
.SPIx = SPI1
};
}
bool Adafruit_RA8875::begin(enum RA8875sizes s) {
//....
// Initialize CS and RST pins as outputs
_cs.init(PP_OUTPUT_MODE, NO_PULL);
_rst.init(PP_OUTPUT_MODE, NO_PULL);
// write CS high and keep it high
_cs.write(GPIO_PIN_SET);
// write RST low then high
_rst.write(GPIO_PIN_RESET);
HAL_Delay(100);
_rst.write(GPIO_PIN_SET);
HAL_Delay(100);
// Initialize SPI
_spi.begin();
uint8_t x = readReg(0);
if (x != 0x75) {
Error_Handler(); // This is where failure happens
return false;
}
initialize();
return true;
}
## SPI transfers ##
void Adafruit_RA8875::writeReg(uint8_t reg, uint8_t val) {
writeCommand(reg);
writeData(val);
}
uint8_t Adafruit_RA8875::readReg(uint8_t reg) {
writeCommand(reg);
return readData();
}
uint8_t Adafruit_RA8875::readData(void) {
_cs.write(GPIO_PIN_RESET);
_spi.begin();
_spi.transfer(RA8875_DATAREAD);
uint8_t x = _spi.transfer(0x0);
_spi.end();
_cs.write(GPIO_PIN_SET);
return x;
}
void Adafruit_RA8875::writeCommand(uint8_t d) {
_cs.write(GPIO_PIN_RESET);
_spi.begin();
_spi.transfer(RA8875_CMDWRITE);
_spi.transfer(d);
_spi.end();
_cs.write(GPIO_PIN_SET);
}
uint8_t SPI::transfer(uint8_t data) {
// Wait until TXE is set (Transmit buffer empty)
while (!(_pSPIx->SR & SPI_SR_TXE));
// Send data
_pSPIx->DR = data;
// Wait until RXNE is set (Receive buffer not empty)
while (!(_pSPIx->SR & SPI_SR_RXNE));
// Return received data
return _pSPIx->DR;
}
void SPI::begin(void) {
_pSPIx->CR1 |= SPI_CR1_SPE;
}
void SPI::end(void) {
while (_pSPIx->SR & SPI_SR_BSY); // Wait until not busy
_pSPIx->CR1 &= ~SPI_CR1_SPE;
}
2024-12-12 02:52 PM
0xFF likely means the controller is not powered, or not correctly connected. It is the absence of a signal. Code and settings presented seem fine.
2024-12-19 04:12 PM
I don't think it's power. There is designated 5V LDO L7805 giving power to both MCU and RA8875. Here is the logic analyzer output. Here is full source code if it helps at all.