This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

simple example of SPI + S110 (on SDK 8.x) ?

Hello,

I wrote a firmware for my project, based on the UART over BLE example, so using the softdevice, establishing connections, etc. It works.

I'd now like to use a sensor connected via SPI. I have looked at the spi_master_with_spi_slave example, but it does not use the softdevice, and I suspect it won't "just work" if I do the same thing, as the softdevice might interfere with interrupts for example. Am I right ?

Does anyone have a simple example of reading and writing data using SPI with SoftDevice enabled (and a BLE connection running) ?

The main problem I'm affraid of is that in some test code I have done with this sensor and without SoftDevice, I have this function :

/**
 * Reads a byte from the specified register in the MFRC522 chip.
 * The interface is described in the datasheet section 8.1.2.
 */
uint8_t PCD_ReadRegister1(	uint8_t reg ) {
	uint32_t err_code;

	m_tx_data[0] = 0x80 | (reg << 1);
	m_tx_data[1] = 0x00;

	m_transfer_done = false;
	err_code = spi_master_send_recv(SPI_MASTER_HW, m_tx_data, 2, m_rx_data, 2);
	APP_ERROR_CHECK(err_code);

	while (!m_transfer_done)
		;

	return m_rx_data[1];
} // End PCD_ReadRegister()

but it ends with a "while (!m_transfer_done), and so it blocks the rest of the execution. How should I rewrite this, but be able to do stuff like :

val = PCD_ReadRegister1(VersionReg);
sprintf(str, "version: 0x%02x\r\n", val);
simple_uart_putstring(str);

(that assumes that PCD_ReadRegister1 returns directly the value, but if I do that I will have a while loop that will block the SoftDevice and other stuff)

?

Thanks for your help

Parents
  • The SPI master works fine with the softdevice. I think all Nordic's library code works fine with the softdevice.

    while() loops don't block the softdevice, it runs on interrupts so your while loop just gets interrupted when it needs service and returns to it later, so it's not a problem. It may not be the most efficient way to do it, but it won't block.

    Don't forget to initialize the spi master with an available IRQ priority, you can't use 0 or 2, you need to use 1 or 3, there are defines for those, "APP_IRQ_PRIORITY_HIGH" and "APP_IRQ_PRIORITY_LOW".

Reply
  • The SPI master works fine with the softdevice. I think all Nordic's library code works fine with the softdevice.

    while() loops don't block the softdevice, it runs on interrupts so your while loop just gets interrupted when it needs service and returns to it later, so it's not a problem. It may not be the most efficient way to do it, but it won't block.

    Don't forget to initialize the spi master with an available IRQ priority, you can't use 0 or 2, you need to use 1 or 3, there are defines for those, "APP_IRQ_PRIORITY_HIGH" and "APP_IRQ_PRIORITY_LOW".

Children
No Data
Related