From ASCII to binary (SPI config)

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

From ASCII to binary (SPI config)

Jump to solution
589 Views
CitRam
Contributor III

Hello!

I'm learning to write code for FRDM KE02Z. I woluld like send binary word via SPI, for example write binary word like  11110111 not ASCII characters. In my task eighth bit must be parity bit. I already tried use parity bit set in Component Inspector/SPI0/Atribute Set List, but KE02 doesen't support SPI pairty bit.

Could you advice me how should I change the subroutine string uint8_t OutData[BLOCK_SIZE] = "FF", for ability writing binary word not ASCII characters.

Below  my code

#define BLOCK_SIZE 4

uint8_t f;

uint8_t OutData[BLOCK_SIZE] = "FF";

uint8_t InpData[BLOCK_SIZE];

volatile LDD_SPIMASTER_TError ComError = 0U;

LDD_TError Error;

LDD_TDeviceData *MySPIPtr;

/* User includes (#include below this line is not maintained by Processor Expert) */

/*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.                    ***/

 

 

 

  MySPIPtr = SM1_Init(NULL);                               /* Initialization of SM1 component */

  //SM1_SelectConfiguration(MySPIPtr, 1U, 1U);               /* Select chip select 1 and attribute set 1 */

  while(1){

  Error = SM1_ReceiveBlock(MySPIPtr, InpData, BLOCK_SIZE);

  //f=atof(OutData);/* Request data block reception */

  Error = SM1_SendBlock(MySPIPtr, OutData, BLOCK_SIZE);    /* Start transmission/reception */

  while (!SM1_GetBlockReceivedStatus(MySPIPtr)) {          /* Wait until data block is transmitted/received */

  SM1_Main(MySPIPtr);

   }

  }

  /* Write your code here */

  /* For example: for(;;) { } */

  /*** 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 main routine. DO NOT MODIFY THIS TEXT!!! ***/

0 Kudos
1 Solution
321 Views
CitRam
Contributor III

I've done. But I dont't know correctly or not Smiley Happy

#include "Cpu.h"

#include "Events.h"

#include "SM1.h"

/* Including shared modules, which are used for whole project */

#include "PE_Types.h"

#include "PE_Error.h"

#include "PE_Const.h"

#include "IO_Map.h"

#define BLOCK_SIZE 4

uint8_t OutData[BLOCK_SIZE];

uint8_t InpData[BLOCK_SIZE];

volatile LDD_SPIMASTER_TError ComError = 0U;

LDD_TError Error;

LDD_TDeviceData *MySPIPtr;

/* User includes (#include below this line is not maintained by Processor Expert) */

/*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.                    ***/

  MySPIPtr = SM1_Init(NULL);                               /* Initialization of SM1 component */

  //SM1_SelectConfiguration(MySPIPtr, 1U, 1U);               /* Select chip select 1 and attribute set 1 */

  while(1){

  Error = SM1_ReceiveBlock(MySPIPtr, InpData, BLOCK_SIZE);

  OutData[0]=255;

  Error = SM1_SendBlock(MySPIPtr, OutData, BLOCK_SIZE);    /* Start transmission/reception */

  while (!SM1_GetBlockReceivedStatus(MySPIPtr)) {          /* Wait until data block is transmitted/received */

  SM1_Main(MySPIPtr);

   }

  Error = SM1_ReceiveBlock(MySPIPtr, InpData, BLOCK_SIZE);

  OutData[1]=254;

  Error = SM1_SendBlock(MySPIPtr, OutData, BLOCK_SIZE);    /* Start transmission/reception */

  while (!SM1_GetBlockReceivedStatus(MySPIPtr)) {          /* Wait until data block is transmitted/received */

  SM1_Main(MySPIPtr);

     }

  }

  /* Write your code here */

  /* For example: for(;;) { } */

  /*** 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 main routine. DO NOT MODIFY THIS TEXT!!! ***/

View solution in original post

0 Kudos
1 Reply
322 Views
CitRam
Contributor III

I've done. But I dont't know correctly or not Smiley Happy

#include "Cpu.h"

#include "Events.h"

#include "SM1.h"

/* Including shared modules, which are used for whole project */

#include "PE_Types.h"

#include "PE_Error.h"

#include "PE_Const.h"

#include "IO_Map.h"

#define BLOCK_SIZE 4

uint8_t OutData[BLOCK_SIZE];

uint8_t InpData[BLOCK_SIZE];

volatile LDD_SPIMASTER_TError ComError = 0U;

LDD_TError Error;

LDD_TDeviceData *MySPIPtr;

/* User includes (#include below this line is not maintained by Processor Expert) */

/*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.                    ***/

  MySPIPtr = SM1_Init(NULL);                               /* Initialization of SM1 component */

  //SM1_SelectConfiguration(MySPIPtr, 1U, 1U);               /* Select chip select 1 and attribute set 1 */

  while(1){

  Error = SM1_ReceiveBlock(MySPIPtr, InpData, BLOCK_SIZE);

  OutData[0]=255;

  Error = SM1_SendBlock(MySPIPtr, OutData, BLOCK_SIZE);    /* Start transmission/reception */

  while (!SM1_GetBlockReceivedStatus(MySPIPtr)) {          /* Wait until data block is transmitted/received */

  SM1_Main(MySPIPtr);

   }

  Error = SM1_ReceiveBlock(MySPIPtr, InpData, BLOCK_SIZE);

  OutData[1]=254;

  Error = SM1_SendBlock(MySPIPtr, OutData, BLOCK_SIZE);    /* Start transmission/reception */

  while (!SM1_GetBlockReceivedStatus(MySPIPtr)) {          /* Wait until data block is transmitted/received */

  SM1_Main(MySPIPtr);

     }

  }

  /* Write your code here */

  /* For example: for(;;) { } */

  /*** 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 main routine. DO NOT MODIFY THIS TEXT!!! ***/

0 Kudos