MCP3901 24 bit SPI

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.
Anonymous
Not applicable

I am attempting to use the SPI master module to interface the MCP3901. The first thing I am doing is setting up the registers to the configuration I want. Then I will attempt to read.

   

I am using a pin on the PSoC to generate the clock. The device is not responding, a sign the configuration did not take. The sign of successful configuration I am looking for is activity on the data ready and MISO pins when invoking a read. I am receiving none.

   

My C code, the SPI object, and the MCP3901 are not squaring up. Given the address automatically increments upon a write, I assumed you can just write the values 8 bits at a time using the SPI master. Can any of you tell where I am mixed up? What about reading 24 bits properly?

   

Attached are the header and C files I am writing.

0 Likes
4 Replies
ruha_285291
Level 2
Level 2

 It will be easier to assist you if you could post the entire project

   

File, Export Project Bundle, Minimum(Basic)

   

SPI can be a bit od an issue, do you have access to a logic ananlyser?

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

A pretty low cost logic analyzer -

   

 

   

http://www.ebay.com/itm/Compatible-with-Saleae-USB-Logic-24MHz-8Ch-Logic-Analyzer-Supports-1-1-15-US...

   

 

   

Just search ebay for "Saleae logic" for other suppliers.

   

 

   

I bought 2, work great.

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

I got the converter to work with the help of a logic analyzer. I forgot I had one (it was packed away from a recent move).

   

Now I am confused by a few things:

   

1. The converter spits out a 24 bit signed integer. How should I read this properly in C? I am attempting this with a union and three bytes. I may have it right but I am also confused by equation 5.3.

   

2. Equation 5-3 is how a voltage count corresponds to a voltage read.

   

http://ww1.microchip.com/downloads/en/DeviceDoc/22192d.pdf

   

The conversion formula I use is Voltage = (ACD_Count * Ref_Voltage) / (2^Resolution). The variables may be rearragned  in the datasheet as I cannot conform if DATA_CHn is the count or the analog voltage. I am using the internal 2.37 volt reference. The in- terminals are grounded, so I am just running the converters single ended. So for this converter, based on that formula, with my setup, what is theproper method to determine the voltage level based on the count?

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

You can store the 3 bytes received from the SPI in a 32-bit integer. Then you get the sign bit (the 24th), mask out the upper 9 bits and set the sign properly.

   

To get the voltage, you just need to re-arrange the formula. Since Vref- and Vin- are 0 for you, formula 5-3 reads as

   

DATA=(Vin/Vref)*max_count*gain*3

   

so you re-arrange it as

   

Vin=(DATA*Vref)/(max_count*gain*3)

0 Likes