AnsweredAssumed Answered

Can't write to SPI data register. MC9S08JM60

Question asked by Sergey Pilipchuk on Jun 29, 2011
Latest reply on Jun 29, 2011 by Sergey Pilipchuk

Hello,

 

I am trying to utilize SPI2 module as SPI Master to read data from a slave device.

 

I have successfully setup SPI1 module as master/bidirectional to send data to another device (without the need to get anything in return).

 

I ran the code in debugger to test it without the slave device yet. The problem is that it won't write data to the SPI2 data registers no matter what I do.

 

Please look at my code and tell me what am I doing wrong.

 

void main(void){  ...  //Initialize SPI2 Module  SPI2C1_SPE = 0;                   //disable SPI2 Module  SPI2C1 = 0b00010011;          //disable SPI Ints, SPI Master Mode 0, SS enabled, data LSB first  SPI2C2 = 0b00010000;          //8-bit mode, data uses MISO & MOSI pins  SPI2BR = 0b00010010;          //set baud rate     SPI2C1_SPE = 1;                   //enable SPI2 Module  temp = Getdata(0xFF);  ...}//*** FUNCTION - Get Databyte Getdata(byte data){  while(SPI2S_SPTEF!=1);        //wait until transmit buffer is empty   SPI2DL = data;                    //send dummy **** THIS DOES NOT WORK **** SPI2DL ALWAYS = 0x00  while(SPI1S_SPRF!=1);         //wait until data is ready in receive data buffer  data = SPI2DL;  return data;  } 

 

Thank you

Outcomes