Kiran Sahni

MC9S08GT60A - SPI / GPIO conflict?

Discussion created by Kiran Sahni on Aug 14, 2007
Latest reply on Aug 15, 2007 by bigmac
I have a MC9S08GT60A interfaced to an ADC (AD7799) using SPI. The ADC is configured to continuously convert values and drop its SDO low whenever values are ready to be read.  SDO goes high while it is in the process of converting; during this time data cannot be read (SDO is high at an approx. 5% duty cycle).
The test program I set up is supposed to enable continuous conversion mode, then wait for SDO to assert low and then clock out the data. The code is below. The code, however, does not yield the proper output.  I am having very hard time figuring out why. When this code is executed, the logic analyzer shows that SDO (MISO on the MCU) is inverted with the pin going high when data is ready and low while converting. Also strange is that SPI read occurs right after SDO goes from low to high so when I sample the data I get 0xFFFFFF, which is very wrong. If I run the program and simply comment out ReadSPI24Bits(&data), SDO (MISO on the MCU) returns to normal. It is only when I sample that SDO becomes inverted.
If I break in the sampling loop, PTED=0x10, PTEPE=0x00, PTESE=0x00, and PTEDD=0x37.
Initially, I thought that since I was trying to use the MISO on the MCU as an input while the SPI module was enabled I could be causing the problem. So I tied pin B2 to MISO and queried B2 to avoid that but still ran into the same inversion problem. So how do I get this silly thing to work? Sorry about the lengthy explaination but I wanted to make sure I covered all the bases. Thank you in advance for any help in solving this problem.
#define SPIS_DummyRead        {char dummy=SPIS}#define SPIDummyWrite         {SPID=0x00}#define WaitSPIRxBufferFull   {while (!(SPIS & 0x80));}#define ChipSelect            {PTED &= ~0x04;}// functions to read 8 bits of data through SPIvoid ReadSPI(uint8_t* byteRead) {   SPIS_DummyRead;   SPIDummyWrite;   WaitSPIRxBufferFull;   *byteRead = SPID;}// functions to read 24 bits of data through SPIvoid ReadSPI24Bits(uint32_t* byteRead) {   uint8_t data1, data2, data3;   uint32_t result;   ReadSPI(&data1);                 // Read 24 bits of data   Wait_6_Clks();   ReadSPI(&data2);   Wait_6_Clks();   ReadSPI(&data3);   result = data1;                  // combine data into one variable   result = result << 8;   result = result + data2;   result = result << 8;   result = result + data3;   *byteRead = result;}void collectData(void) {   uint32_t data;   SPIC1 = 0x5C;   SPIC2 = 0x00;   ChipSelect;   // omitted code to set up ADC, I know that is ok   // after ADC is setup, get data   while (1) {      // sample only if pin B2 is low      if (!(PTBD & 0x04)) {         ReadSPI24Bits(&data);      }   }}
Added p/n to subject.

Message Edited by NLFSJ on 2007-08-14 09:43 AM