EmbeddedRelated.com
Forums
Memfault Beyond the Launch

Help needed with spi interfacing to mcp3208 and ads7871

Started by santogiuseppe May 1, 2013
Hello,
so far i succeeded to interface the minicore 6750 (and the rcm4000) with max4820, max31865 (an RTD-to-Digital Converter) and a touchscreen display but i have serious problems with ads7871 and mcp3208
I dont know what's the problem, the spi's signals (cs, miso, mosi and the serial clock) are connected to a logic analyzer,
and the communication (cs, clock and the mosi from the minicore) seems ok, but i'm not receiving the chips replies!!(and i'm going MAD!!)
I use the same spi with other chips, and i changed the cs only to connect these chips
Maybe it's the schematics...there is someone who succeeded to interface with the ads787x or mcp320x chips family and is so kind to share the schematics?
Thanks in advance

On 5/1/2013 2:51 PM, santogiuseppe wrote:
> Hello,
> so far i succeeded to interface the minicore 6750 (and the rcm4000) with max4820, max31865 (an RTD-to-Digital Converter) and a touchscreen display but i have serious problems with ads7871 and mcp3208
> I dont know what's the problem, the spi's signals (cs, miso, mosi and the serial clock) are connected to a logic analyzer,
> and the communication (cs, clock and the mosi from the minicore) seems ok, but i'm not receiving the chips replies!!(and i'm going MAD!!)
> I use the same spi with other chips, and i changed the cs only to connect these chips
> Maybe it's the schematics...there is someone who succeeded to interface with the ads787x or mcp320x chips family and is so kind to share the schematics?
> Thanks in advance

I have used the MCP3208. Here is the code:

unsigned read_atod(int chan)
{
unsigned txbits,rxbits;
txbits=0x01; // start bit
outi(PEDR,srPEDR&=~PORTE_ADCS);
SPIWrite(&txbits,1);
txbits=0x80 | (chan<<4);
SPIWrRd(&txbits,&rxbits,2);
outi(PEDR,srPEDR|=PORTE_ADCS);
return swapb(rxbits);
}

This was for Softools, outi() is similar to WrPortI(), it just sets the
CS line low/high. The function swapb() swaps the high/low bytes as they
are received, high/low and I need low/high.

You also need to consider if the SPI library is sending data MSB first
or not. That is determined if SPI_NOREV is defined.

--
------
Scott G. Henion, Consultant
Web site: http://SHDesigns.org
------

--- In r..., Scott Henion wrote:
[cut]
> > Maybe it's the schematics...there is someone who succeeded to
interface with the ads787x or mcp320x chips family and is so kind to
share the schematics?
> > Thanks in advance
>
> I have used the MCP3208. Here is the code:
>
> unsigned read_atod(int chan)
> {
> unsigned txbits,rxbits;
> txbits=0x01; // start bit
> outi(PEDR,srPEDR&=~PORTE_ADCS);
> SPIWrite(&txbits,1);
> txbits=0x80 | (chan<<4);
> SPIWrRd(&txbits,&rxbits,2);
> outi(PEDR,srPEDR|=PORTE_ADCS);
> return swapb(rxbits);
> }
>
> This was for Softools, outi() is similar to WrPortI(), it just sets
the
> CS line low/high. The function swapb() swaps the high/low bytes as
they
> are received, high/low and I need low/high.
>
> You also need to consider if the SPI library is sending data MSB first
> or not. That is determined if SPI_NOREV is defined.
>
> --
> ------
> Scott G. Henion, Consultant
> Web site: http://SHDesigns.org
> ------
>

Thank you mister Scott!!
Although i dont think it's the protocol, and i dont think it's the spi
configuration, because to try the spi code i use a loop where i can
interactively change the spi settings: msb/lsb , clock speed, spi mode
etc
I just tried your way to communicate with the chip (with dynamic c it's
slightly different but not much), that is to send a byte with the start
bit and next the byte that sets single/differential conversion and the
channel to sample and...doesnt work [:(]
My way (following the datasheet suggestion) is a bit different in the
bits sequence i send (i blank the leading 5 zeros, not the leading 7 as
in your method), but the gist of it is exactly the same, on the logic
analyzer i see that the bit sequence i send is correct, but there are
not replies from the chip...
I think the problem is that the communication with the chip doesn't
happen at all
The datasheet says "If the device was powered up with the CS pin low (as
in my case), it must be
brought high and back low to initiate communication."
Then - to reset the chip before using it - i send the sequence CS HI -
delay (few microseconds) - CS LOW - delay - CS HI
Do you use a similar sequence to reset the chip?
Thank you very much for the answer

Memfault Beyond the Launch