AnsweredAssumed Answered

SPI ReadBlock doesn't work

Question asked by Juan Pablo Echeverria on May 30, 2016
Latest reply on Aug 1, 2016 by Juan Pablo Echeverria

Using PE and the example found in help I'm not able to read a response of a AD7794 DAC that I have in a custom PCB.

 

I checked the code and SPI PE configuration several times and I'm sure to have a correct configuration, however  the driver are not able to read the block.

 

I suppose to reset the DAC sending 32 consecutive bits with ones (that works perfect), later I read an ID register, but the driver don't send the clock signals to read the response or even the CS lines either.

 

Inside of the function AD7794_Init there is a SM1_ReceiveBlock that never happen.

 

LDD_TError AD7794_Reset()
{
  unsigned char dataRst[5];
  dataRst[0] = 0b11111111;
  dataRst[1] = 0b11111111;
  dataRst[2] = 0b11111111;
  dataRst[3] = 0b11111111;

  if( SM1_SendBlock(SM1_DeviceData, (LDD_TData *)dataRst, (uint16_t) 4) == ERR_OK )
  {
  while (!SM1_GetBlockSentStatus(SM1_DeviceData))
  {
   SM1_Main(SM1_DeviceData);
  }
  }else{
  return ERR_OK; // to catch errors
  }
}

LDD_TError AD7794_Init()
{
  unsigned char dataInit[2] = { AD7793_COMM_READ | AD7793_COMM_ADDR(AD7793_REG_ID), 0x00 };
  if( SM1_SendBlock(SM1_DeviceData, (LDD_TData *)dataInit, (uint16_t) 1) == ERR_OK )  {
  while (!SM1_GetBlockSentStatus(SM1_DeviceData))  {
   SM1_Main(SM1_DeviceData);
  }
  }else{
  return ERR_OK; // to catch errors
  }
  unsigned char dataRX[4] = { 0x00, 0x00, 0x00, 0x00 };
  if( SM1_ReceiveBlock(SM1_DeviceData, (LDD_TData *)dataRX, (uint16_t) 1) == ERR_OK )
  {
  while(!SM1_GetBlockReceivedStatus(SM1_DeviceData))
  {
  SM1_Main(SM1_DeviceData);
  }
  }else{
  return ERR_OK; // to catch errors
  }
}

LDD_TError AD7794_GetStatus(unsigned char *_status)
{
  unsigned char data = AD7793_COMM_READ | AD7793_COMM_ADDR(AD7793_REG_STAT);
  if(SM1_SendBlock(SM1_DeviceData, (LDD_TData *)&data, (uint16_t) 1) == ERR_OK )
  {
  while (!SM1_GetBlockSenStatus(SM1_DeviceData))
  {
   SM1_Main(SM1_DeviceData);
  }
  }else{
  return ERR_OK; // to catch errors
  }

  if( SM1_ReceiveBlock(SM1_DeviceData, (LDD_TData *)_status, (uint16_t) 1) == ERR_OK )
  {
  while(!SM1_GetBlockReceivedStatus(SM1_DeviceData))
  {
  SM1_Main(SM1_DeviceData);
  }
  }else{
  return ERR_OK; // to catch errors
  }
  return ERR_OK;
}

/*lint -save  -e970 Disable MISRA rule (6.3) checking. */
int main(void)
/*lint -restore Enable MISRA rule (6.3) checking. */
{
  /* Write your local variable definition here */
  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
  PE_low_level_init();
  /*** End of Processor Expert internal initialization.                    ***/
  /* Write your code here */
  SM1_SelectConfiguration(SM1_DeviceData, 0U, 0U);
  AD7794_Reset();
  AD7794_Init();

  unsigned char bufferRX[4] = { 0x00, 0x00, 0x00, 0x00 };
  //AD7794_GetStatus(bufferRX);
  /*while(1){
   AD7794_GetStatus(bufferRX);
   bufferRX[0] = 0x00;
  }*/
  /*** Don't write any code pass this line, or it will be deleted during code generation. ***/
  /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
  #ifdef PEX_RTOS_START
    PEX_RTOS_START();                  /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
  #endif
  /*** End of RTOS startup code.  ***/
  /*** 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 mainroutine. DO NOT MODIFY THIS TEXT!!! ***/

 

the ndBlock(SM1_Devi

ndBlock(SM1_Devi

Attachments

Outcomes