Hi,
I have enabled SPIM on nRF52810 and worked normally.But when I enabled on nRF52832, it worked unusual.
I had defined CONFIG_NFCT_PINS_AS_GPIOS because used P0.9 and P10. Is there any other settings different between nRF52810 and nRF52832?
Hi,
I have enabled SPIM on nRF52810 and worked normally.But when I enabled on nRF52832, it worked unusual.
I had defined CONFIG_NFCT_PINS_AS_GPIOS because used P0.9 and P10. Is there any other settings different between nRF52810 and nRF52832?
Hi,
Can you try to reduce the SPIM speed to see if that impact the issue? Do you have a logic analyzer trace to look at for comparison?
Kenneth
Hi,
Can you try to reduce the SPIM speed to see if that impact the issue? Do you have a logic analyzer trace to look at for comparison?
Kenneth
We had this intermittent issue when using NFC pins as gpio a couple of years ago. This happened at any speed. It was very hard to find.
TWI (SPI not tested) works for us: using CONFIG_NFCT_PINS_AS_GPIOS and nRF52832 2. rev and P0.2/SCL, P0.9/SDA @100kHz/400kHz.
Should we expect any troubles?
I need to correct my problem.
I have defined SPI GPIO:
SCK: P0.4
MISO: P0.5
MOSI: P0.6
SS: P0.7
And the SPI sensor need another IO write or read to read/write data.
RST:P0.8
BUSY: P0.9
DIO1: P0.10
Here is my GPIO configration:
#define SPI_SCK_PIN 4 #define SPI_MISO_PIN 5 #define SPI_MOSI_PIN 6 #define SPI_SS_PIN 7 #define RADIO_nRESET_PIN 8 #define RADIO_BUSY_PIN 9 #define RADIO_DIO1_PIN 10 nrf_gpio_cfg_input(RADIO_DIO1_PIN, NRF_GPIO_PIN_PULLUP); nrf_gpio_cfg_input(RADIO_BUSY_PIN, NRF_GPIO_PIN_PULLUP); nrf_gpio_cfg_output(RADIO_nRESET_PIN); nrf_gpio_pin_set(RADIO_nRESET_PIN); nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG; // spi_config.ss_pin = NRF_DRV_SPI_PIN_NOT_USED; spi_config.miso_pin = SPI_MISO_PIN; spi_config.mosi_pin = SPI_MOSI_PIN; spi_config.sck_pin = SPI_SCK_PIN; // spi_config.frequency = SPI_FREQUENCY_FREQUENCY_K250; // spi_config.irq_priority = 4; nrf_gpio_cfg_output(SPI_SS_PIN); nrf_gpio_pin_set(SPI_SS_PIN); APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, spi_event_handler, NULL));
When the application worked on nRF52832 custom board, the SPI will read wrong data, I'll show you logic analyzer trace
latter.
Is the NFC pin occur uncertainly voltage even I defined CONFIG_NFCT_PINS_AS_GPIOS?
I'll upload the software or hardware if you need.
Logic analyzer trace:
My application code:
#define SPI_SCK_PIN 4
#define SPI_MISO_PIN 5
#define SPI_MOSI_PIN 6
#define SPI_SS_PIN 7
#define RADIO_nRESET_PIN 8
#define RADIO_BUSY_PIN 9
#define RADIO_DIO1_PIN 10
nrf_gpio_cfg_input(RADIO_DIO1_PIN, NRF_GPIO_PIN_PULLUP);
nrf_gpio_cfg_input(RADIO_BUSY_PIN, NRF_GPIO_PIN_PULLUP);
nrf_gpio_cfg_output(RADIO_nRESET_PIN);
nrf_gpio_pin_set(RADIO_nRESET_PIN);
nrf_delay_ms(500);
uint8_t SpiInOut( uint8_t txBuffer)
{
uint8_t m_rx=0;
uint32_t timeout = 10000;
spi_xfer_done = false;
APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, &txBuffer, 1, &m_rx, 1));
while (!spi_xfer_done)
{
__WFE();
}
NRF_LOG_INFO("SPI RX:%02x TX:%02x",m_rx,txBuffer);
return m_rx;
}
void SpiIn( uint8_t *txBuffer, uint16_t size )
{
uint8_t m_rx_buff[255]={0};
uint32_t timeout = 10000;
spi_xfer_done = false;
APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, txBuffer, size, m_rx_buff,NULL));
while (!spi_xfer_done)
{
__WFE();
}
}
void spi_event_handler(nrf_drv_spi_evt_t const * p_event,
void * p_context)
{
spi_xfer_done = true;
}
void m_spi_lora_init(void)
{
nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
// spi_config.ss_pin = NRF_DRV_SPI_PIN_NOT_USED;
spi_config.miso_pin = SPI_MISO_PIN;
spi_config.mosi_pin = SPI_MOSI_PIN;
spi_config.sck_pin = SPI_SCK_PIN;
// spi_config.frequency = SPI_FREQUENCY_FREQUENCY_K250;
// spi_config.irq_priority = 4;
nrf_gpio_cfg_output(SPI_SS_PIN);
nrf_gpio_pin_set(SPI_SS_PIN);
APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, spi_event_handler, NULL));
nrf_delay_ms(100);
// m_lora_init(LORA_INIT_MODE);
m_lora_check();
NRF_LOG_INFO("LORA initialized.");
}
void m_lora_check(void)
{
uint8_t data[2]={0x12,0x34};
uint8_t test[2]={0,0};
while(1)
{
Radio.WriteBuffer(0x06C0,data,2);
Radio.ReadBuffer(0x06C0,test,2);
if((test[0]==data[0])&&(test[1]==data[1]))
{
NRF_LOG_INFO("Lora SUCCESS");
m_tag_type.check[TAG_LORA] = TAG_CHECK_SUCCESS;
}else
{
NRF_LOG_INFO("Lora FAIL %02x %02x",test[0],test[1]);
m_tag_type.check[TAG_LORA] = TAG_CHECK_ERROR;
}
nrf_delay_ms(1000);
NRF_LOG_FLUSH();
}
}
const struct Radio_s Radio =
{
RadioInit,
RadioGetStatus,
RadioSetModem,
RadioSetChannel,
RadioIsChannelFree,
RadioRandom,
RadioSetRxConfig,
RadioSetTxConfig,
RadioCheckRfFrequency,
RadioTimeOnAir,
RadioSend,
RadioSleep,
RadioStandby,
RadioRx,
RadioStartCad,
RadioSetTxContinuousWave,
RadioRssi,
RadioWrite,
RadioRead,
RadioWriteBuffer,
RadioReadBuffer,
RadioSetMaxPayloadLength,
RadioSetPublicNetwork,
RadioGetWakeupTime,
RadioIrqProcess,
// Available on SX126x only
RadioRxBoosted,
RadioSetRxDutyCycle
};
void RadioWriteBuffer( uint16_t addr, uint8_t *buffer, uint8_t size )
{
SX126xWriteRegisters( addr, buffer, size );
}
void SX126xWriteRegisters( uint16_t address, uint8_t *buffer, uint16_t size )
{
SX126xCheckDeviceReady( );
nrf_gpio_pin_clear(SPI_SS_PIN);
SpiInOut(RADIO_WRITE_REGISTER );
SpiInOut(( address & 0xFF00 ) >> 8 );
SpiInOut( address & 0x00FF );
for( uint16_t i = 0; i < size; i++ )
{
SpiInOut(buffer[i] );
}
nrf_gpio_pin_set(SPI_SS_PIN);
SX126xWaitOnBusy( );
}
void RadioReadBuffer( uint16_t addr, uint8_t *buffer, uint8_t size )
{
SX126xReadRegisters( addr, buffer, size );
}
void SX126xReadRegisters( uint16_t address, uint8_t *buffer, uint16_t size )
{
SX126xCheckDeviceReady( );
nrf_gpio_pin_clear(SPI_SS_PIN);
SpiInOut(RADIO_READ_REGISTER );
SpiInOut(( address & 0xFF00 ) >> 8 );
SpiInOut( address & 0x00FF );
SpiInOut( 0 );
for( uint16_t i = 0; i < size; i++ )
{
buffer[i] = SpiInOut(0 );
}
nrf_gpio_pin_set(SPI_SS_PIN);
SX126xWaitOnBusy( );
}
I suggest to reduce the SPI frequency to check if that have any impact on the issue, also it might be useful to measure the pins with an analog input to check if they are logic high/low, or marginally out of spec.
Kenneth