Question about SPI

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Question about SPI

Post 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.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Question about SPI

Post 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
Post Reply