Hello,
I have what might be a very trivial problem for someone more experienced with these older processors than me.
I am trying to communicate with the ADS1243 ADC via SPI. On the scope everything seems fine however when I try to read the SPIBUF register in the code I always receive a "stupid" response. Normally either 0x00 or 0xFF.
This sample code snippet with debug (written for Keil but easily understandable) shows me simply trying to read the Mux register which is at its PORST value of 0x01 (and proven by the scope). It always returns a value of 0xFF. Does anyone have any ideas to point me in the right direction? (I know there are one or two redundant lines like the "clearing" of the SPIBUF before continuing - I could just ignore that and move on, but for the purposes of showing what I had tried with flag clearing etc, I left them in.
SelectADC(); spiVal = pSPI2->SPIBUF; // Send Write Register command pSPI2->SPIDAT0 = (ADC_READ_FROM_REG | ADC_REG_MUX); // discard spibuf contents spiVal = pSPI2->SPIBUF; // length to respond - write (value + one) byte pSPI2->SPIDAT0 = 0x00; // discard spibuf contents spiVal = pSPI2->SPIBUF; if (pSPI2->SPICTRL3 & 0x01) { TXByteUART(0x11); //prove flag is clear before moving on } // allow byte to be returned 50 cycles min for (i = 0; i<32; i++ ); // wait for result to be produce pSPI2->SPIDAT0 = ADC_READ_DUMMY; // tx no data to receive resp. TXByteUART(0xAA); while (!(pSPI2->SPICTRL3 & 0x01)); //wait for message, should be redundant in sync protocol if (pSPI2->SPICTRL3 & 0x01) { TXByteUART(0x22); //just to check flag is set! } spiVal = pSPI2->SPIBUF; TXByteUART(spiVal); TXByteUART(0xAD); TXByteUART('\n'); //sprintf( textBuf, "Ret'd Val 0x%2X\n", spiVal ); //TXStringUART((unsigned char*)textBuf); DeselectADC();
Kindest thanks in advance,
Andrew