Estoy convirtiendo la biblioteca arduino-nrf905 para stm8s. Hay una función spi en la biblioteca de arduino, es SPI.Transfer(uint8_t reg). Esta función puede escribir y leer spi. Pero, hay dos funciones en la biblioteca periférica stm8s. Estas funciones son SPI_SendData(uint8_t reg) y SPI_ReceiveData(void).
Código de transferencia SPI de la biblioteca arduino:
byte SPIClass::transfer(byte _data) {
SPDR = _data;
while (!(SPSR & _BV(SPIF)))
;
return SPDR;
}
SPI_SendData de la biblioteca STM8S:
void SPI_SendData(uint8_t Data)
{
SPI->DR = Data; /* Write in the DR register the data to be sent*/
}
SPI_ReceiveData de stm8s
uint8_t SPI_ReceiveData(void)
{
return ((uint8_t)SPI->DR); /* Return the data in the DR register*/
}
Quiero convertir este código a stm8s, pero no funciona.
código arduino:
((uint8_t*)data)[i] = spi_transfer(NRF905_CMD_NOP);
Código STM8S:
SPI_SendData(NRF905_CMD_NOP);
((uint8_t*)data)[i] = SPI_ReceiveData();
¡Gracias!
Hay banderas en las que debe esperar, banderas que indicarán cuándo se realiza la transmisión SPI o se ha recibido un byte. Prueba esto:
while (SPI_GetFlagStatus(SPI_FLAG_TXE) == RESET); // wait for any previous data to be sent; checks if the Transmit Register is empty
SPI_SendData(NRF905_CMD_NOP);
while (SPI_GetFlagStatus(SPI_FLAG_RXNE) == RESET); // wait for a byte to come in; checks if the Receive register is not empty
((uint8_t*)data)[i] = SPI_ReceiveData();
vladimir cravero