Andrey Polonsky

SPI problems for MC1321x programming in C

Discussion created by Andrey Polonsky on Dec 10, 2008
Latest reply on Mar 11, 2009 by Andrey Polonsky
Hello,

I am having trouble reading from the internal modem of an MC13212.  I have my code below and I am expecting to see a reset value of 0x007F from register GPIO_dir as per section 5.14 in document MC1321xRM.pdf and instead I am seeing 0x0000.  Please note that in my code I am using local port registers simply as a means to monitor the output.  Any suggestions will be greatly appreciated.

Thanks and regards,
drdr

/********************************/
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */

#define  ce_L        PTED_PTED2

void readREG() {

  PTEDD = 0xff;     //set the ce_L pin as output
  
  SPI1C1 = 0x54;   //=01010100 to enable SPI, disable interrupts, standard operation (tried 0x50)
  ce_L = 0;             //intiate transfer of three bytes

  while(!SPI1S_SPTEF);      //wait for SPI1D to be ready for 1st transfer
  SPI1D=0x8B;                     //initiate transfer to read from register GPIO_dir (0B) in modem
  while(!SPI1S_SPRF);        //wait for SPI1D to receive data from modem
  PTADD=SPI1D;                 //meaningless data -> just using PTADD to clear flag

  while(!SPI1S_SPTEF);      //wait for SPI1D to be ready for 2nd transfer
  SPI1D=0xFF;                     //send anything to get 1st byte of data
  while(!SPI1S_SPRF);        //wait for SPI1D to receive data from modem
  PTBDD=SPI1D;                //correctly received 0x00 in PTBDD
 
  while(!SPI1S_SPTEF);     //wait for SPI1D to be ready for 3rd transfer
  SPI1D=0x86;                     //send anything to get 2nd byte of data
  while(!SPI1S_SPRF);       //wait for SPI1D to receive data from modem
  PTCDD=SPI1D;               //expecting 0x7F but instead get 0x00 in PTCDD again!

  ce_L = 1;                           //terminate transfer of three bytes
 
}

void main(void) {

  EnableInterrupts;              //enable interrupts
  ce_L=1;                            //will start high when its output is enabled
  readREG();       

  for(;:smileywink: {
    __RESET_WATCHDOG(); /* feeds the dog */
  } /* loop forever */
}

Outcomes