industrialNETworXnetx

Rainer Versteeg

Rainer Versteeg

| 06.10.2008 | 13:00 | 7 replies

Reading from an external ADC or MMC over SPI Interface

HI,

I want to read data from an external ADC or MMC over an SPI interface ?
Gives there an example ?

Wich RX_PERIPHERAL_TYPE_SPI configuration must I set to configure the MMC ?

I have an NXDB500 SYS board with an MMC card.

Br,
Rainer

Andreas Jacob

Andreas Jacob

Hilscher Gesellschaft fuer Systemautomation mbH

| 06.10.2008 | 15:11

Hi,

the rcX does not have any dedicated drivers for ADC or MMC. You have to setup the SPI interface as described in the config manual.
You must select the used CS and the used mode. For the handling you have to create your own functions.

Rainer Versteeg

Rainer Versteeg

| 06.10.2008 | 15:46

HI AJ,

Is this the right configuration for the SPI on the MMC:

STATIC CONST RX_SPISLAVE_SET_T tSpiOwlan211g = {
    {"SPI_MMC",RX_PERIPHERAL_TYPE_SPI,0},
    0,                    /* index of the slave's spi port */
    1,                    /* index of the slave's chip select */
    RX_SPI_MODE0,         /* spi mode for this slave device */
    RX_SPI_SPEED_1_0MHz,  /* clock speed for this slave */
    0,                    /* size of a burst block */
    0                     /* delay between 2 burst blocks */
};

Where i can find the information ?

Br,
Rainer

Andreas Jacob

Andreas Jacob

Hilscher Gesellschaft fuer Systemautomation mbH

| 07.10.2008 | 08:36

Hi,

you should know, on which CS your SD card is connected.
The speed and the mode comes from the data sheet of the used SD card.

Rainer Versteeg

Rainer Versteeg

| 07.10.2008 | 08:41

HI AJ,

Thank you !

The SD Card is 1 MB. How can I write data with an offset to the SD Card.

I know only the command:

RX_RESULT erXRes; // error code
  RX_HANDLE hSpi;

UINT8 bSendBuf[4] = { 0xd4, 0x00, 0x00, 0x00 };

erXRes = Drv_SpiSend (hSpi, 4, bSendBuf);

Br,
Rainer

M T

M T

Hilscher Gesellschaft für Systemautomation mbH

| 07.10.2008 | 13:16

SD/MMC Cards do need a special protocol.

It is not a simple Drv_SpiWriteSpi, to write to the cards flash memory. You will need to program a special protocol described in MMC Card Specification V4.3 available from mmca.org or jedec.org (alternatively from any MMC card manufacturer, i.e. SanDisk).

It is simply not enough to just send/recv data on spi.

Regards

MT

Rainer Versteeg

Rainer Versteeg

| 09.10.2008 | 09:45

HI,

We want to speak with 10 ADC. Is it possible to decode the CS0..SC2 Register to speak to 10 ADC:

/*
************************************************************
*   Configuration of the SPI Instances
************************************************************
*/
STATIC CONST FAR RX_SPISLAVE_SET_T atrXSpi[] = {
  { {"SYSSPI1",RX_PERIPHERAL_TYPE_SPI,0}, 
    0,                                    /* Bus port 0                       */
    0,                                    /* Chip select 0                    */
    RX_SPI_MODE3,                         /* spi mode 3                       */
    RX_SPI_SPEED_1_0MHz,                  /* Speed is 1 Mhz                   */
    0,                                    /* No Burst block support           */
    0,                                    /* No delay between bursts          */
  },
  { {"SYSSPI2",RX_PERIPHERAL_TYPE_SPI,0}, 
    0,                                    /* Bus port 0                       */
    1,                                    /* Chip select 0                    */
    RX_SPI_MODE3,                         /* spi mode 3                       */
    RX_SPI_SPEED_1_0MHz,                  /* Speed is 1 Mhz                   */
    0,                                    /* No Burst block support           */
    0,                                    /* No delay between bursts          */
  },
  { {"SYSSPI3",RX_PERIPHERAL_TYPE_SPI,0}, 
    0,                                    /* Bus port 0                       */
    2,                                    /* Chip select 0                    */
    RX_SPI_MODE3,                         /* spi mode 3                       */
    RX_SPI_SPEED_1_0MHz,                  /* Speed is 1 Mhz                   */
    0,                                    /* No Burst block support           */
    0,                                    /* No delay between bursts          */
  }    
};

//=============== 0 / 0 =====================
erXRes = Drv_SpiOpen(hSpi2, RX_INFINITE);
if( erXRes!=RX_OK)
{
return erXRes;
}
erXRes = Drv_SpiSlaveDeselect(hSpi2);
if( erXRes!=RX_OK)
{
return erXRes;
}
erXRes = Drv_SpiClose(hSpi2);
if( erXRes!=RX_OK)
{
return erXRes;
}
erXRes = Drv_SpiOpen(hSpi3, RX_INFINITE);
if( erXRes!=RX_OK)
{
return erXRes;
}
erXRes = Drv_SpiSlaveDeselect(hSpi3);
if( erXRes!=RX_OK)
{
return erXRes;
}
erXRes = Drv_SpiClose(hSpi3);
if( erXRes!=RX_OK)
{
return erXRes;
}
erXRes = Drv_SpiOpen(hSpi1, RX_INFINITE);
if( erXRes!=RX_OK)
{
return erXRes;
}
erXRes = Drv_SpiSend(hSpi1, 1, bSendBuf1);
if( erXRes!=RX_OK)
{
return erXRes;
}
erXRes = Drv_SpiClose(hSpi1);
if( erXRes!=RX_OK)
{
return erXRes;
}

//=============== 0 / 1 =====================
erXRes = Drv_SpiOpen(hSpi2, RX_INFINITE);
if( erXRes!=RX_OK)
{
return erXRes;
}
erXRes = Drv_SpiSlaveDeselect(hSpi2);
if( erXRes!=RX_OK)
{
return erXRes;
}
erXRes = Drv_SpiClose(hSpi2);
if( erXRes!=RX_OK)
{
return erXRes;
}
erXRes = Drv_SpiOpen(hSpi3, RX_INFINITE);
if( erXRes!=RX_OK)
{
return erXRes;
}
erXRes = Drv_SpiSlaveSelect(hSpi3);
if( erXRes!=RX_OK)
{
return erXRes;
}
erXRes = Drv_SpiClose(hSpi3);
if( erXRes!=RX_OK)
{
return erXRes;
}
erXRes = Drv_SpiOpen(hSpi1, RX_INFINITE);
if( erXRes!=RX_OK)
{
return erXRes;
}
erXRes = Drv_SpiSend(hSpi1, 1,bSendBuf2);
if( erXRes!=RX_OK)
{
return erXRes;
}
erXRes = Drv_SpiClose(hSpi1);
if( erXRes!=RX_OK)
{
return erXRes;
}

usw...

Or how is it possible ?

Br,
Rainer

M T

M T

Hilscher Gesellschaft für Systemautomation mbH

| 09.10.2008 | 12:21

SPI Chipselects are usually used to access a single device. Therefore the rcX SPI driver (and usually SPI drivers on other systems) can only assign 1 CS to a slave object.

So if you want to "misuse" the CS signal to drive an external Multiplexer, you will need to program the SPI unit itself, as the rcX driver cannot handle this.

BTW: I am not sure how you want to multiplex 3 CS signals to query 10 ADCs. IMHO you can only decode 8 chip selects from 3 bits with a simple muxer (But I would prefer to only use 7, as 1 state should be used to keep all deselected). :?:

Maybe a solution would be to use external Pins (PIO/GPIO, etc.) and manually drive them as chip selects and save the Call to Drv_SpiSlaveSelect.

Regards

MT

Login