AnsweredAssumed Answered

mc9s12dp512 SPI interfacing problems

Question asked by Florentin von Frankenberg on Nov 12, 2009
Latest reply on Nov 19, 2009 by Daniel Lundin

Hi,

I am trying to use the processor expert SPI bean to help establish communication between my MCU and a sensor. I know very little about how SPI works, and am having difficulty trouble-shooting the problem. Does the hcs12 store any data being sent from the slave in a buffer, which can then be read at a later time using the RecvChar command?

 

A potential problem is that the hcs12 only seems to run the clock (SCLK) signal while it is sending data, and I can't figure out how to get it to run during the time when it is supposed to be receiving a signal. Also, I don't see a way to modify or pick the clock speed. I have attached the document which describes the SPI  interface on my sensor, and posted my code below.


/* Including used modules for compiling procedure */
#include "Cpu.h"
#include "Events.h"
#include "SPI3.h"
#include "Inhr1.h"
#include "Inhr2.h"
#include "Inhr3.h"
#include "SRREADY.h"
#include "PORTP0.h"
#include "PORTP1.h"
#include "PORTP2.h"
#include "PORTP3.h"
/* Include shared modules, which are used for whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"

//constants
int SPI_DELAY = 100;

//vars
int response=0;

int skipperoo=0;
   byte recvd1=0;
  byte recvd2=0;
  int reply=0;

int SPIcommand(byte command, byte operand)
{


  PORTP0_SetVal();
  PORTP1_ClrVal();
 
  SPI3_SendChar(command);
  SPI3_SendChar(operand);

  PORTP0_ClrVal();
  PORTP1_SetVal();

  //while(!SRREADY_GetVal());
//  while(!PORTP2_GetVal());
  Cpu_Delay100US(SPI_DELAY);

  PORTP0_SetVal();
  PORTP1_ClrVal();

  SPI3_RecvChar(&recvd1);
  SPI3_RecvChar(&recvd2);

  reply = recvd1;
  reply <<= 8;
  reply += recvd2;

  return reply;
}

void main(void)
{
  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
  PE_low_level_init();
  /*** End of Processor Expert internal initialization.                    ***/



  for(;;)
  {
       response = SPIcommand(4,0);

    PORTP3_NegVal();

    //Cpu_Delay100US(1*SPI_DELAY);
  }
  /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
  for(;;){}
  /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/

 


 

Message Edited by Franklin on 2009-11-12 06:41 PM
Message Edited by t.dowe on 2009-11-13 09:49 AM

Outcomes