[Answered] SPI Read Register Delay
[Answered] SPI Read Register Delay
Hi,
Quick question here. I have been using the esp-idf spi api successfully by using the spi_device_transmit api. However I have run into a situation with a device that I need to insert a 75 us delay between writing the register address to read from and the time the data is ready to read. The way I understand the spi_device_transmit is that everything is queued up into a transaction I do not see any way to insert any delays.
Pseudo of what I need to do:
SetChipSelectPin(0);
SPIWrite(RegisterAddress);
Delay(75us); // How do I add this??
rxData = SPIWrite(RegisterAddress);
SetChipSelectPin(1);
Hopefully I explained my question. I am a little new to using the SPI bus. So my apologies if I am missing something easy.
Thanks!
Quick question here. I have been using the esp-idf spi api successfully by using the spi_device_transmit api. However I have run into a situation with a device that I need to insert a 75 us delay between writing the register address to read from and the time the data is ready to read. The way I understand the spi_device_transmit is that everything is queued up into a transaction I do not see any way to insert any delays.
Pseudo of what I need to do:
SetChipSelectPin(0);
SPIWrite(RegisterAddress);
Delay(75us); // How do I add this??
rxData = SPIWrite(RegisterAddress);
SetChipSelectPin(1);
Hopefully I explained my question. I am a little new to using the SPI bus. So my apologies if I am missing something easy.
Thanks!
Last edited by qjones on Thu Mar 02, 2017 4:04 pm, edited 1 time in total.
Re: SPI Read Register Delay
Just a guess ... but instead of one SPI transaction with two data interactions ... could we not use two SPI transactions with one data interaction each?
For example:
For example:
Code: Select all
spi_device_transmit();
delay(period);
spi_device_transmit();
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
Re: SPI Read Register Delay
I thought about this. I just have not had a chance to try it yet. I am still new to the ends and outs of the SPI bus particularly now that I am trying to write some of my own device interfaces. However the way I understand it is that the CS line will get toggled with each of the spi_device_transmit(). I could assume that the data loaded from the read register on the 1st transaction would just get shifted out on the next go around. But I feel like there will be a chance to miss some data depending on the clock and timings that are also happening on the back end for setup. Just trying to make sure I am not doing any bad practices or am not trying to code around some easy. Worst case I will just use the esp32-hal-spi api from the arduino side. Seems unnecessary but not the end of the world while everything gets ironed out on this new chip.
Re: SPI Read Register Delay
For my own curiosity, what is the nature of the SPI slave device? Do we have a reference to a data sheet on it?
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
Re: SPI Read Register Delay
It is the ADNS-3080 optical mouse sensor. Very cool board. I am needing to use it for some basic image processing and possibly for optical flow position calculations on a project. It's an older chip and this seems to be the best link.
https://people.ece.cornell.edu/land/cou ... s_3080.pdf
On page 11 you will see the register read delays of 50us and 75us for the motion registers. There have been plenty of arduino and mbed libraries that have interfaced it but all those seem to have the capabilities to set these intermittent delays in the SPI transmission. I haven't hooked the esp32 up to a scope or analyzer yet so for all I know this 75us delay is already covered.... Anyway it would make a great chip for one of your video snippets
Thanks,
https://people.ece.cornell.edu/land/cou ... s_3080.pdf
On page 11 you will see the register read delays of 50us and 75us for the motion registers. There have been plenty of arduino and mbed libraries that have interfaced it but all those seem to have the capabilities to set these intermittent delays in the SPI transmission. I haven't hooked the esp32 up to a scope or analyzer yet so for all I know this 75us delay is already covered.... Anyway it would make a great chip for one of your video snippets
Thanks,
-
- Posts: 9709
- Joined: Thu Nov 26, 2015 4:08 am
Re: SPI Read Register Delay
Hmm, the ESP32 may also have the hardware to do something like this... lemme check; I have a driver update in the queue anyway, may as well enable this when the hardware can do it.
Edit: Ah, this is not going to keep the CS from going high while waiting, by the way. The SPI bus in the ESP32 is pretty optimized for high-speed transfers, and in general changing timing parameters (which is what you want to do with your delay) is not common. If you truly want to do this, you may need to implement SPI in software by bitbanging. That being said, I am pretty sure the chip you have in mind won't mind the read and write being in separate transfers.
Edit: Ah, this is not going to keep the CS from going high while waiting, by the way. The SPI bus in the ESP32 is pretty optimized for high-speed transfers, and in general changing timing parameters (which is what you want to do with your delay) is not common. If you truly want to do this, you may need to implement SPI in software by bitbanging. That being said, I am pretty sure the chip you have in mind won't mind the read and write being in separate transfers.
Re: SPI Read Register Delay
Sounds like a job for dummy bits and disable clk during dummy phase.
-
- Posts: 9709
- Joined: Thu Nov 26, 2015 4:08 am
Re: SPI Read Register Delay
Ah, you're right, you may be able to get around it that way.
Re: SPI Read Register Delay
Can you explain a little further. I see the dummy bits, and I believe I see where to set the clock disable in spi_dev_t struct definition. But I don't see an easy way to set this without a modified spi_master.c. I will keep looking but I am probably missing something here... I thought I had the spi portion vetted out and go figure I need to use the one random chip doing something atypical. Keeps it exciting anyway.WiFive wrote:Sounds like a job for dummy bits and disable clk during dummy phase.
Thanks!
Re: SPI Read Register Delay
You can use transactions without CS and (de)activate CS pin in software:qjones wrote:... However the way I understand it is that the CS line will get toggled with each of the spi_device_transmit()...
Code: Select all
spi_device_interface_config_t devcfg={
.clock_speed_hz=10000000, //Clock out at 10 MHz
.mode=0, //SPI mode 0
.spics_io_num=-1, //NO CS PIN USED
};
Who is online
Users browsing this forum: MicroController and 247 guests