MC9S08GT60A - SPI / GPIO conflict?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MC9S08GT60A - SPI / GPIO conflict?

2,086 Views
nareec
Contributor I
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.
  
Code:
#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
Labels (1)
0 Kudos
Reply
1 Reply

879 Views
bigmac
Specialist III
Hello,
 
I am not familiar with the AD7799, but here are a few observations -
 
I notice you have a macro to enable ChipSelect, but not to disable it.  What are the chip select requirements of the AD7799?  I might expect that this should be released after each reading.  While monitoring SDO as a "ready" signal, does chip select need to be enabled?
 
To monitor the MOSI pin while a SPI transfer is not occurring, this pin would need to revert to GPIO.  Therefore the SPI module will need to be disabled during the monitoring process, and re-enabled just prior to commecing the read process.  This is because the SPI peripheral function will over-ride the GPIO facility.
 
Are your CPHA and CPOL settings compatible with the AD7799?
 
Is there a particular reason for using continuous conversion mode for the ADC?  An alternative approach could be to initiate the next conversion following the read of the previous conversion.  KBI interrupt on falling SDO might be used to process each reading.
 
Regards,
Mac
 
0 Kudos
Reply