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

nRF52832 SPI tagging for multi-channel ADC?

Hi,

I have successfully connected an MCP3004 to the nRF52832 and can assign the ADC channel 0 output to a characteristic value. Works beautifully.

However, there are three other channels I want to use on the ADC for other sensors and the method to query the ADC over the SPI bus uses a bitmap to select the channel in the initial query.

The problem is the SPI event that occurs.

I presently will not know which channel is being returned in a given event.

Is there a method to tag the initial transfer with some indicator of which channel is being requested? Perhaps some other clever way?

Maybe having different rx buffers and a map of which buffer pertains to which channel?

Thanks!

Parents
  • Hi,

    Are you using the SPI master driver in the SDK? Your solution of using multiple rx buffers might work, but you will need some way to know which buffer contain valid data. If you are OK with reading "old data", you can setup a rx buffer for each channel and update the characteristics from all channels on each SPI callback, but this will generate additional work for the CPU.

    An alternative is to use the p_context pointer to signalize to the event handler which channel is in use. Unfortunately this pointer is set on the interface initialization, and not on the execution of a transfer. You will then have to uninit and initialize the SPI interface for each transfer. In SDK 13 you can also use the SPI transaction manager, which can take a pointer, p_user_data as argument, and pass this to the event handler. This takes advantage of the p_context pointer in the SPI master driver, and will automatically uninit and init the SPI interface if the parameters change.

    Are you starting multiple transaction simultaneously, or use EasyDMA with the SPI peripheral? If not, you can simply set a flag indicating which channel is read and check this in the SPI event handler.

    Best regards,

    Jørgen

Reply
  • Hi,

    Are you using the SPI master driver in the SDK? Your solution of using multiple rx buffers might work, but you will need some way to know which buffer contain valid data. If you are OK with reading "old data", you can setup a rx buffer for each channel and update the characteristics from all channels on each SPI callback, but this will generate additional work for the CPU.

    An alternative is to use the p_context pointer to signalize to the event handler which channel is in use. Unfortunately this pointer is set on the interface initialization, and not on the execution of a transfer. You will then have to uninit and initialize the SPI interface for each transfer. In SDK 13 you can also use the SPI transaction manager, which can take a pointer, p_user_data as argument, and pass this to the event handler. This takes advantage of the p_context pointer in the SPI master driver, and will automatically uninit and init the SPI interface if the parameters change.

    Are you starting multiple transaction simultaneously, or use EasyDMA with the SPI peripheral? If not, you can simply set a flag indicating which channel is read and check this in the SPI event handler.

    Best regards,

    Jørgen

Children
No Data
Related