Multiple Devices on SPI Bus

rith87
Posts: 3
Joined: Thu Aug 17, 2023 12:43 am

Multiple Devices on SPI Bus

Postby rith87 » Wed Jan 17, 2024 11:58 pm

Hello folks,

I have a DM9051 and a CC1201 running on the same SPI Bus. Both of them use polling transactions (spi_device_polling_transmit()) and work fine together most of the time. However, occasionally, I'll get a few errors like:
E (54778) spi_master: spi_device_acquire_bus(977): Cannot acquire bus when a polling transaction is in progress.
E (54788) spi_master: spi_device_polling_start(1043): Cannot send polling transaction while the previous polling transaction is not terminated.

What is the best practices approach when working with multiple devices on the same SPI bus? Suppose the following scenario:
  • Task 1 calls spi_device_acquire_bus()
  • Task 1 calls spi_device_polling_transmit() and sets the polling flag to true
  • Task 2 calls spi_device_acquire_bus()
At this point, I would have expected Task 2 to wait until Task 1 has called spi_device_release_bus() but looking at the code, it seems like it fails instead?

Code: Select all

SPI_CHECK(!spi_bus_device_is_polling(device), "Cannot acquire bus when a polling transaction is in progress.", ESP_ERR_INVALID_STATE );
So, does this mean that the best practice here is to do some error checking and retrying when calling spi_device_acquire_bus()?

joseMiguel
Posts: 22
Joined: Sun Oct 25, 2020 11:43 pm

Re: Multiple Devices on SPI Bus

Postby joseMiguel » Thu Jan 18, 2024 7:36 am

Hi,

Sorry, if it is a silly question
I suppose that you have two CS (Chip Select "CS" or not Chip Select "nCS")
One for each external circuit?

Regards

José Michel
José Michel

rith87
Posts: 3
Joined: Thu Aug 17, 2023 12:43 am

Re: Multiple Devices on SPI Bus

Postby rith87 » Thu Jan 18, 2024 5:08 pm

Yup, the CC1201 and DM9051 share the same SPI bus but they have their own individual CS line.

Who is online

Users browsing this forum: No registered users and 88 guests