Need help fr setting spi on kml25z

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

Need help fr setting spi on kml25z

623 Views
piergiusepperan
Contributor II

Hello, I'm trying to use for my first time the kinetis software with processor expert and I want to set up the SPI to send digital value to a DAC. I started by including from the component library Init_SPI. I selected my MOSI pin, I disabled the MISO, because my MKL25Z must only send the data to a slave, DAC, (I don't know if it is correct), now, I don't know if I have to set up the SS (slave selected) pin or not? I don't know if I have to include the SPI_MasterLDD from the component library or not. Can you guide me or show me an example? thank you

0 Kudos
3 Replies

334 Views
vfilip
NXP Employee
NXP Employee

Hi,

I don't know if I have to set up the SS (slave selected) pin or not?

You should check the Slave device signal specification. Sometimes is needed to toggle SS pin by GPIO instead of by SPI peripheral. CPOL, CPHA settings should be double-checked on your side too.

I don't know if I have to include the SPI_MasterLDD from the component library or not.

  • Init. component just initialize the SPI peripheral and together with PDD macros provides low level run-time functionality but there will be much more coding on your side.
  • SPI_MasterLDD - I would recommend remove the SPI init component from the project and use this component instead. It will initialize the SPI peripheral too + provide run-time API. When you right click on the LDD component you always find typical usage section in the help.

best regards

Vojtech Filip

0 Kudos

334 Views
piergiusepperan
Contributor II

Ok thanks. I have setted up the SPIMaster_LDD, so, the output pin the clock pin the clock period and so on, How can I create the function to send  data? are there specific function? I don't know how can I find it

0 Kudos

334 Views
marek_neuzil
NXP Employee
NXP Employee


Hello,

If you open the Help of the SPIMaster_LDD component (open the context menu of the SPIMaster_LDD component in the Components windows and select the Help on Component command), you can find code examples on the Typical Usage page of the component's help. For example (SPIMaster_LDD without interrupts):

#define BLOCK_SIZE 4

uint8_t OutData[BLOCK_SIZE] = "0123";

uint8_t InpData[BLOCK_SIZE];

volatile LDD_SPIMASTER_TError ComError = 0U;

LDD_TError Error;

LDD_TDeviceData *MySPIPtr;

void main(void)

{

  ...

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

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

  Error = SM1_ReceiveBlock(MySPIPtr, InpData, BLOCK_SIZE); /* 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);

  }

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

  Error = SM1_ReceiveBlock(MySPIPtr, InpData, BLOCK_SIZE); /* 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);

  }

}

Best Regards,

Marek Neuzil

0 Kudos