PSOC5 SPI and AD7793

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

cross mob
lock attach
Attachments are accessible only for community members.
JoLo_284096
Level 4
Level 4
First like received

Dear all:

   

I am trying to communicate with analog Devices part AD7793 using SPI with a PSOC5.

   

I have CY8CKIT-050 and the AD7793 Evalutaion KIT (I need more ADC channels so I need AD7793 for these extra channels). I wired the signals mosi, miso, cs , clk and GND beween both EVK.

   

AD support this devices with a generic diver that can be download from http://wiki.analog.com/resources/tools-software/uc-drivers/renesas/ad7793

   

I also attach the project on PSOC with a vey simple main.c. I Just want to check the AD7793 is there using function AD7793_init();.

   

I am not able to talk with AD7793. Can anyone have a look to the SPI communication function and check if there is any wrong.?

   

Thanks in advance,

   

Joaquin.

0 Likes
14 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

In Communication.c, SPI_Write() you send your data using SPIM_WriteTxData(). This will put the data into the SPIM's FIFO and returns before the data has been actually sent. When you now remove your ss-signal the communication fails. Better is to wait until the FIFO is empty AND the last byte is transmitted before pulling the control-register high again.

   

 

   

Bob

0 Likes
JoLo_284096
Level 4
Level 4
First like received

Dear Bob:

   

Thank you very much for your repply. After some trying  I added the following sentence after the for bucle SPIM_WriteTxData...:

   

for(i=0u; i<bytesNumber; i++){
                SPIM_WriteTxData(data); // initiates data transmission
            }
        }
 while(!(SPIM_ReadTxStatus() & SPIM_STS_SPI_IDLE));

   

On datasheet, figure on page 28/41, it seems that everything is finihed when SPI_IDLE is set, so I added the last sentence.

   

 

   

Stll I have other problem on the SPI_Read function, I cant see the clock moving...any idea of the reason?

   

Thanks in advance.

   

Joaquin.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Can you post your complete project, so that we all can have a look at all of your settings? To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.



Bob
 

0 Likes
lock attach
Attachments are accessible only for community members.
JoLo_284096
Level 4
Level 4
First like received

yes, of course...

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Reading from an SPI slave takes a little bit of getting used to.

   

SPI is organized, so that for every bit written to the slave a bit is returned by the slave at the very same time.

   

So the usual procedure to read from a slave is:

   

 

   
        
  • Assert  ss
  •     
  • Write byte(s) to slave to indicate what the slave has to answer (commands).
  •     
  • When done (transmitted), clear the recieve buffer
  •     
  • Write as many dummy bytes to the slave as you want to read.
  •     
  • When done (transmitted), de-assert ss
  •     
  • Now your RX-buffer is filled with the required information which you can read out now.
  •    
   

 

   

Seems to be a bit (or byte) weired, but that's the way SPI works.

   

 

   

Happy coding

   

Bob

0 Likes
JoLo_284096
Level 4
Level 4
First like received

Hi Bob,

   

Thank you very much.

   

It was clear that I did not understand SPI.... Still i dont understand what all the AD functions do, but at least I am able to detect the chip.

   

Another small question: One of the AD functions need to detect when Dout/RDY pin of the chip AD7793 is low for the end of conversion. For my system,  it is miso signal pin...can I use miso_read() to read this pin and check when it is low ?

   

Thank you very much for your help.

   

Regards,

   

Joaqui.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Since miso is an input pin with a given pin name you may use

   

m_miso_pin_Read()

   

to get its current value (0 or 1)

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
JoLo_284096
Level 4
Level 4
First like received

Hello Bob:

   

Still I am having sporadic problems with the SPI comunicating with AD7793. I mean , sometimes it goes right but  others go wrong. Not pretty sure if the problem comes from the SPI comunication or in the Analog Devices functions to interact with it.

   

But just to be sure that SPI  subrutines (just only two, SPI_Write()  and SPI_read() )  are Ok, could you have a look to them and let me know if you see any problem?

   

I left the whole project but only on comunication.c/h is where I would like you  have a look.

   

Thanks in advance,

   

Joaquin.

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Just out of curiosity why are you using an external DelSig and not the DelSig in

   

PSOC 5LP ? It has an onchip ref, buffer with G for A/D input, and muxes. It does not

   

have an IA, you would need one external if you needed high G in the signal path as

   

5LP is limited to G = 8, but the buffer is differential in case you need that.

   

 

   

   

 

   

Regards, Dana.

0 Likes
JoLo_284096
Level 4
Level 4
First like received

Yes, no problem.

   

We are designing a kind of PLC measuring 6 different temperatures (PT100 and Thermocouple Type K) using the PSOC 5 ADC, 2 DA output , 16 Digital Inputs, 8 digital outputs and also we need 4 analog sensors (4-20mA, 0-5V and 0-10V)  for which we will use two external AD7793. All of processed by  a RaspberryPi....

   

Joaquin.

0 Likes
JoLo_284096
Level 4
Level 4
First like received

Hello:

   

I am tryng to find an Application Note  regarding communication with an external device usign SPI . Can someone recommend me one? All the examples I find are between PSOC devices.

   

Thanks in advance,

   

Joaquin.

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

This might help, although for PSOC 1, principles are same.

   

 

   

www.cypress.com/

   

 

   

Regards, Dana.

0 Likes
JoLo_284096
Level 4
Level 4
First like received

Hi Dana:

   

Thank you very much.

   

As it is for PSOC1 it is not fully applicable for PSOC5 and I get some confused because I havent work with PSoC 1 before. Any other suggestion? 

   

Thanks in advance,

   

Joaquín.

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

There is always the SPI examples in PSOC Creator, start page, "Find Example project".

   

 

   

There is some stuff up on youtube for SPI training, in general, not PSOC specific.

   

 

   

Regards, Dana.

0 Likes