Page 1 of 1

Question about SPI

Posted: Fri Jun 01, 2012 7:23 am
by Tectu
Hello Folks,

I need your help here: I try to use the ADS7843 Touchpad controller on my TFT LCD Module. Here's the timing diagram:
Image

From my understanding, I have to do the following:

Code: Select all

spiSend(0x90)  // for read out X-Axis
foo = spiReceive()
spiSend(0x00)
result = spiReceive()
spiSend(0x00)
result = (result << 8) | spiReceive()


What is the easiest way to do that using ChibiOS SPI driver? I also have trouble with the SPI configuration. In CR1 there are the bits BIDIMODE and BIDIOE. I don't think that I have to change the BIDIOE myself when writing/reading.

What I tried:

Code: Select all

static void spicb(SPIDriver *spip);
static const SPIConfig spicfg = {
    NULL,
    GPIOC,
    TP_CS,
    SPI_CR1_BR_2 | SPI_CR1_BR_1 | SPI_CR1_BR_0,
};

void tpInit(void) {
    spiStart(&SPID1, &spicfg); 
}

uint16_t tpReadX(void) {
    uint16_t rx;

    SET_CS(0);
    spiSend(&SPID1, 1, 0x90);
    spiReceive(&SPID1, 1, &rx);
    spiSend(&SPID1, 1, 0x00);
    spiReceive(&SPID1, 1, &rx);
    spiSend(&SPID1, 1, 0x00);
    spiReceive(&SPID1, 1, &rx);  // I know I'd have to shift here
    SET_CS(1);
}



Thanks for your help.

Re: Question about SPI

Posted: Fri Jun 01, 2012 7:36 am
by Giovanni
I think you need to do a spiExchange() for the first byte followed by a spiReceive() for the next two bytes. I am not sure if you need to synchronize with the busy signal, the SPI driver doesn't do that by itself.

You don't need to touch any register when using the driver, it is all handled internally.

Giovanni