Sending adc data to ESP32 using SPI

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
jadkh
Level 2
Level 2
First solution authored 10 replies posted 10 sign-ins

Hello Infineon World! 

I'm using PSoC 5LP (CY8KIT-59) and I'm reading the data of a 3 axial accelerometer using the 3 ADCs. I want to send the 3 axis values continuously to the ESP32 (SPI) 

First the PSoC5LP will work as a master or a slave? 

Should I use the DMA request buffer to send it to the ESP32? I can see there's no digital output in the ADCs in TopDesign, but only in the main we can get it by calling ADC_GetResult() 

How to send all 3 axis' data to one component (ESP32)

Sorry I am new to SPI and PSOC

0 Likes
1 Solution

Jad,

Whether you use 3 ADCs with no AMux or 1 ADC with a 3-input AMux, the cross-talk would be about the same.  There are advanced ways to minimize the cross-talk but that discussion is for another day.

Looking at the sensor's spec, the maximum per axis sample rate is 6 Ksps.  With 16-bit resolution,  that is 12 KBps.  Using a UART with 8N1, the datarate needed by the UART is 120Kbps.  Close to the standard 115.2Kbps rate.

To transmit 3 axis of data you would need a minimum of 360Kbps.  This is possible with most CPUs.

Natural resonance of the system

Since you are using an accelerometer it is intended to be installed on a system.  The intended system has a maximum natural resonance.  This resonance will be lower if the system has more mass.  (It's a momentum factor).  Therefore, you need to determine the natural resonance of your system.  If it is a heavy system, the resonance will be at a low frequency. Therefore the effective sensor sample  rate can be lower.   

For example, an automobile has a very low resonant frequency because of its large mass.  A sample rate 100 Hz is usually sufficient.

Therefore the output to the ESP32 can be 1Kbps for one axis and 3Kbps for 3 axises.

You can still sample at the 6Ksps for each axis but implement a SW averaging scheme to create a SW LPF to filter output sensor and environmental noise that includes possible cross-talk.  The resultant axis average can be pushed to the ESP32 at 3Kbps for 3 axises.

Len
"Engineering is an Art. The Art of Compromise."

View solution in original post

0 Likes
9 Replies
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

jadkh,


First the PSoC5LP will work as a master or a slave? 


Either.  The PSoC5 has SPI Master and SPI Slave components.  Which one you use will be dependent on which modes the ESP32 can accept.  Can your ESP32 act as a slave?  If not, you're forced to configure the PSoC5 as a slave.


Should I use the DMA request buffer to send it to the ESP32? I can see there's no digital output in the ADCs in TopDesign, but only in the main we can get it by calling ADC_GetResult() 


The PSoC5 ADC has a EOC (End Of Conversion) digital output.  You can use that signal to trigger an interrupt to move the data via CPU or by DMA.


How to send all 3 axis' data to one component (ESP32)


Sending all three axis into a single ESP32 SPI comm channel can be complicated.  You can setup a "SPI  virtual register" implementation.  This is where the SPI master as a "register addressing" scheme.  You would then implement each Axis as a separate "register".  The SPI Master would first  pass the  desired "register address" (X, Y or Z) and then wait for the SPI Slave to send the data in the next set of SPI clocks.

Have you considered using a high-speed UART implementation?   Using this type of comm, you can set the PSoC5 as the Tx-only and the ESP32 as the Rx-only.   You can then create a packet structure that has the following form:

<header byte><X axis data><Y axis data><Z axis data><endofheader byte>

This structure would be repeated on every sample set. 

Len
"Engineering is an Art. The Art of Compromise."
0 Likes

How to setup this virtual register to implement axes as seperate reg? (using the control reg?); you're not talking about mutiplexing the 3 ADCs output neither ? is it a solution? 

 

About the high speed UART, I use the SW_Tx_UART component and send the packet to a pin that i connect to the ESP32 right? 

The packet structure:  can I comine the ADC outputs using sprintf and then send it with PutString? 

can you tell me what do you mean with header and endofheader byte ? and how can I implent it 

 

Thanks 

 

Jad 

 

 

0 Likes
Krupashankar
Moderator
Moderator
Moderator
500 replies posted 50 likes received 25 likes received

Hi @jadkh,

Could you please refer to this code example: https://www.cypress.com/documentation/code-examples/ce95358-sar-sampling-spi-and-usbuart-communicati...

This code example illustrates the usage of SPI to transfer the SAR ADC data from 4 analog channels which is similar to getting ADC data from 3 channel and sending it via SPI.

Question: First, the PSoC5LP will work as a master or a slave?

It can be configured either way based on the application. In your case, you can use PSoC5lp as Master and configure ESP32 as an SPI slave.

Question: Should I use the DMA request buffer to send it to the ESP32? I can see there's no digital output in the ADCs in TopDesign, but only in the main we can get it by calling ADC_GetResult() 

Please refer to the above example for sending the data buffer, You can use DMA for faster data access.

Please let us know for any further clarifications.

 

Thanks,

Krupashankar

 

0 Likes

Hello 

Thank you 

The project you reffered to me is outdated and I cannot see 90 percent of the components

if I understood, you mutiplexed the inputs to the adc, convert the value of the selected Mux channel and send it via UART and SPI. 

in my case, I have 3 adcs that I would like to read their output simultaneously. Multiplexing could slow down the process and I would fight a cross talk between channels. 

Can you screenshot the topdesign of the project if your version is compatible? 

thanks

 

 

Jad

0 Likes

Jad,

Whether you use 3 ADCs with no AMux or 1 ADC with a 3-input AMux, the cross-talk would be about the same.  There are advanced ways to minimize the cross-talk but that discussion is for another day.

Looking at the sensor's spec, the maximum per axis sample rate is 6 Ksps.  With 16-bit resolution,  that is 12 KBps.  Using a UART with 8N1, the datarate needed by the UART is 120Kbps.  Close to the standard 115.2Kbps rate.

To transmit 3 axis of data you would need a minimum of 360Kbps.  This is possible with most CPUs.

Natural resonance of the system

Since you are using an accelerometer it is intended to be installed on a system.  The intended system has a maximum natural resonance.  This resonance will be lower if the system has more mass.  (It's a momentum factor).  Therefore, you need to determine the natural resonance of your system.  If it is a heavy system, the resonance will be at a low frequency. Therefore the effective sensor sample  rate can be lower.   

For example, an automobile has a very low resonant frequency because of its large mass.  A sample rate 100 Hz is usually sufficient.

Therefore the output to the ESP32 can be 1Kbps for one axis and 3Kbps for 3 axises.

You can still sample at the 6Ksps for each axis but implement a SW averaging scheme to create a SW LPF to filter output sensor and environmental noise that includes possible cross-talk.  The resultant axis average can be pushed to the ESP32 at 3Kbps for 3 axises.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
lock attach
Attachments are accessible only for community members.
Krupashankar
Moderator
Moderator
Moderator
500 replies posted 50 likes received 25 likes received

Hi @jadkh,

You can update the PSoC component from Project -> Update Components and try building the project.

PFA existing code example with updated components for reference.

The maximum sample rate of ADC is 384ksps at 8-bit resolution. For 16 bit resolution, it is 48ksps. Could you please tell us what is ADC sampling rate which is required for each channel.

 

Thanks,

Krupashankar

 

0 Likes
WaMa_286156
Level 5
Level 5
First comment on blog 100 replies posted 50 replies posted

If the psoc is 5 volts, keep in mind the ESP32  module is 3.3 volts and driving it from a 5 volt PSOC could cause a problem.

In that case, use pull up resistors to the 3.3v on the ESP module, and set the psoc outputs to be open collector.  use high impedance inputs on the psoc, and you are good to go.

 

0 Likes

jadkh,

WaMa is correct.  However can be simple using a very low external component count.

On the PSoC5LP there is port12.  It is a SIO port it has special features if you set it up properly in TopDesign.

These port pins have the ability to do level-translation from the PSoC5LP @ 5V and to the ESP @ 3.3V

Check out the Cypress Appnote AN60580_SIO_Tips_and_Tricks_in_PSoC_3_PSoC_5LP-ApplicationNotes-v10_00-EN.pdf chapter 6.  It covers the configuration needed to have a '0' external component level translator from 5V to 3.3V.

 

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
WaMa_286156
Level 5
Level 5
First comment on blog 100 replies posted 50 replies posted

Ah, Yes.  
If you can get the 3.3 volts into a PSOC pin, you can dispense with the Pull Up resistors when using an SIO pin, and make its output 3.3v compatible without external components.  <head slap> <grin>

Thanks, Len!  I missed that!

0 Likes