SPI interfacing code for frdm-ke06z

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

SPI interfacing code for frdm-ke06z

954 Views
shailavsurve
Contributor II

Hello,

I want to read data of my slave device which is at register address 0x00 through SPI. I am trying to develop the code using PE. I am attaching my code with this. Can anyone give me suggesstions?

My slave device has following data at register address 0x00

src_addr[dest_addr[0]] = 0x3b;

  src_addr[dest_addr[1]] = 0xea;

src_addr[dest_addr[2]] = 0x01;

  src_addr[dest_addr[3]] = 0x00;

  src_addr[dest_addr[4]] = 0x81;

  src_addr[dest_addr[5]] = 0x22;

  src_addr[dest_addr[6]] = 0xFE;

  src_addr[dest_addr[7]] = 0x45;

  src_addr[dest_addr[8]] = 0x00;

src_addr[dest_addr[9]] = 0x31;

src_addr[dest_addr[10]] = 0xC1;

  src_addr[dest_addr[11]] = 0x73;

  src_addr[dest_addr[12]] = 0xc8;

  src_addr[dest_addr[13]] = 0x40;

  src_addr[dest_addr[14]] = 0x00;

  src_addr[dest_addr[15]] = 0x00;

  src_addr[dest_addr[16]] = 0x90;

  src_addr[dest_addr[17]] = 0x00;

  src_addr[dest_addr[18]] = 0x7A;*/

 

I want to read this with my master frdm-board. I am first trying to develop pe code for frdm-kl25z. But my actual project requires to develop spi code for frdm-ke06z. So any help with both the controllers or any will be appreciated.

Thanks,

Shailav

Original Attachment has been moved to: cw.rar

Labels (1)
Tags (2)
0 Kudos
7 Replies

722 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Shailav,

Have you test your project on board ? What about it ? What about the question when you run ?

We can refer to the error come up with special point .

BR

Alice

0 Kudos

722 Views
shailavsurve
Contributor II

Hello Alice,

I have tried doing this

  for(;;){

      for(i=0;i<19;i++)

      {

      OutData[i]=0;

      SM1_SendBlock(SM1_DeviceData, OutData, DATA_SIZE);  

      }

  /* Master sends message 1  */

  printf("\n\nMaster: Sending message1...\n");  

  SM1_ReceiveBlock(SM1_DeviceData, master_receive, DATA_SIZE);

  printf("%c \r\n", master_receive[0]);

   /* waiting for transferring completed  */

  MasterReceivedFlg = FALSE;

  while(!MasterReceivedFlg);

I am sending outdata so that I can read back 19 bytes from slave.

My thinking is as follows to do this.

1) I have to send 19 bytes 0x00.

2) The slave will get the register address 0x00 and it will give me back the data on address 0x00.

I am using master_receive for this.

Can you modify code further?

Thanks,

Shailav

0 Kudos

722 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Shailav,

Do you want  save the receive data  at one specified address (for example 0x00) in salve ?

then send the data of this place ?

If yes, you can use the relocate data function place the array OutData[i] to one place , for example  0x1FFFF000

__attribute__ ((section(".myRAM"))) int OutData[10];

In the linker file :

.mySection :

{

*(.myRAM)

} > m_data_1FFF0000

About the detail please refer to  Relocating Code and Data Using the CW GCC Linker File for Kinetis

Please pay attention that we can not place the array to the address 0x0000, for in this place it save the interrupt

vector :

pastedImage_1.png

Hope it helps

Alice

0 Kudos

722 Views
shailavsurve
Contributor II

Hello,

My code is as below. In my code I am not able to receive data from by slave device. My code is as below

/* Including needed modules to compile this module/procedure */

#include "Cpu.h"

#include "Events.h"

#include "Pins1.h"

#include "SM1.h"

#include "SS1.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"

#include "PDD_Includes.h"

#include "Init_Config.h"

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

#include "stdio.h"

#include <string.h>

/* Global Variables */

#define DATA_SIZE 2

#define DATA_SIZ 2

#define BLOCK_SIZE 13

volatile bool SlaveReceivedFlg = FALSE;

volatile bool MasterReceivedFlg = FALSE;

int master_send[20] = {0,0,0,0,0,0,0,0,0,0,0,9,8,7,6,5,4,3,2,1};

int slave_send[1] = ; int master_receive[20] ; int slave_receive[1] = ;

uint8_t OutData[BLOCK_SIZE] = {0,1,2,3,4,5,6,7,8};

uint8_t InpData[BLOCK_SIZE];

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

uint32 i = 0;

/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/

PE_low_level_init();

/*** End of Processor Expert internal initialization. ***/

SM1_Init(SM1_DeviceData);

for(;;){

SM1_SendBlock(SM1_DeviceData, master_send, DATA_SIZE);

SM1_ReceiveBlock(SM1_DeviceData, master_receive, DATA_SIZ);

MasterReceivedFlg = FALSE;

/// while(!MasterReceivedFlg);

SM1_SendBlock(SM1_DeviceData, master_send, DATA_SIZE);

SM1_ReceiveBlock(SM1_DeviceData, master_receive, DATA_SIZE);

MasterReceivedFlg = FALSE;

while(!MasterReceivedFlg);

for(i=0;i<10000000;i++){} //Delay

}

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

/* END main */

/*!

0 Kudos

722 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Shailav,

Sorry so long to reply you . Maybe your problem have been resolved .

If not ,please first use one logic analyzer check whether there is signal on the receive

BR

Alice

0 Kudos

722 Views
shailavsurve
Contributor II

Hello Alice,

Yes my problem has been solved.

Thanks,

Shailav

0 Kudos

722 Views
shailavsurve
Contributor II

Hello,

This is what I want to do.

My slave device has some data as I mentioned in my first comment.

I have my master controller that is frdm-ke06z.

I want to read the data from my slave device.

I want to print that data through uart.

My data at slave device which is other controller is as follows:

src_addr[dest_addr[0]] = 0x3b;

// src_addr[dest_addr[1]] = 0xea;

/* src_addr[dest_addr[2]] = 0x01;

src_addr[dest_addr[3]] = 0x00;

src_addr[dest_addr[4]] = 0x81;

src_addr[dest_addr[5]] = 0x22;

src_addr[dest_addr[6]] = 0xFE;

src_addr[dest_addr[7]] = 0x45;

src_addr[dest_addr[8]] = 0x00;

src_addr[dest_addr[9]] = 0x31;

src_addr[dest_addr[10]] = 0xC1;

src_addr[dest_addr[11]] = 0x73;

src_addr[dest_addr[12]] = 0xc8;

src_addr[dest_addr[13]] = 0x40;

src_addr[dest_addr[14]] = 0x00;

src_addr[dest_addr[15]] = 0x00;

src_addr[dest_addr[16]] = 0x90;

src_addr[dest_addr[17]] = 0x00;

src_addr[dest_addr[18]] = 0x7A;*/

Can you modify the code that I attached?

Thanks,

Shailav

0 Kudos