SPIMaster_LDD usage

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

SPIMaster_LDD usage

跳至解决方案
2,310 次查看
gschelotto
Contributor V

Hello,

I need to read 2 bytes from one 12-bit ADC using the SPI interface in MKE02Z. I select SPIMaster_LDD from PE and I configure it as shown:

  • No Interrupt service/event
  • Output pin MOSI not used (I only want to read 2 bytes through MISO)
  • No Chip Select is used (I use a GPIO instead)
  • Clock rate: 0.5us
  • Auto initialization: Enabled

For the driver initialization I do:

SM1_Enable(SM1_DeviceData);

And for reading 2 bytes

Error = SM1_ReceiveBlock(SM1_DeviceData, SPI_in_data, 2);

while (!SM1_GetBlockReceivedStatus(SM1_DeviceData))

     SM1_Main(SM1_DeviceData);

The implementation is very easy but... It does not work as I cannot see the 16 clock on SCLK as expected.

Could someone give me a hint?

regards,

gaston

1 解答
1,707 次查看
marek_neuzil
NXP Employee
NXP Employee

Hello Gaston,

The MKE02Z derivative provide allocation of all SPI pins based on SPE bit in the SPI Control Register 1. There is not possible do disable allocation of the MOSI pin on this derivative (see the reference manual).

The delay between bytes can be caused by other interrupts routines or by the SPI interrupt routine itself. What is the bus/core clock frequency of the CPU? You can try to use higher core and bus clock frequency.

Best Regards,

Marek Neuzil

在原帖中查看解决方案

0 项奖励
回复
6 回复数
1,707 次查看
DavidS
NXP Employee
NXP Employee

Hi Gaston,

Attached is a FRDM-KE02Z SPIMaster_LDD project that uses SPI0 and I jumpered J9 pins 2-4.

I used the Component Help as a guide.

Regards,

David

0 项奖励
回复
1,707 次查看
gschelotto
Contributor V

Hi David,

I see this in the code you've attached:

Error = SM1_ReceiveBlock(MySPIPtr, InpData, BLOCK_SIZE); /* Request data block reception */

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

But I don't want to send bytes (OutData) through MOSI (pin39, PTE1). Why I have to use a sending function (SendBlock) in order to receive packets (ReceiveBlock)? I don't understand this method. In my application PTE1 is configured as general purpose digital output. If I use the code above, I see unwanted changes on PTE1 because of the SendBlock() function. I've configured this pin as shown here below but the changes on PTE1 persist.

Untitled.png

What can I do to solve this?

regards,

gaston

0 项奖励
回复
1,707 次查看
marek_neuzil
NXP Employee
NXP Employee

Hello Gastom,

The SPI device must send and receive data concurrently and the SPI device must send data to receive any data (see the block diagram and functionality description of the SPI in a reference manual). It also means that the ReceiveBlock() method just prepare a buffer to receive data (it does not initiate the receive transfer) and you must use the SendBlock() method to initiate the data transfer (one byte is sent and received concurrently). When you don't use the MOSI pin (the internal signal is not routed on a pin) and the data are not physically transmitted but it does not affect functionality of the SPI device.

Therefore you must use the sequence of ReceiveBlock() and SendBlock() to receive any data.

Best Regards,

Marek Neuzil

1,707 次查看
gschelotto
Contributor V

Therefore you must use the sequence of ReceiveBlock() and SendBlock() to receive any data.

Marek, thank you for the clarification

When you don't use the MOSI pin (the internal signal is not routed on a pin) and the data are not physically transmitted but it does not affect functionality of the SPI device.

How can disable the MOSI pin? I'm not able to uncheck it in the component Settings

One more thing. I've tested 2-bytes reception using ReceiveBlock() and SendBlock() as suggested. It works but there is a big gap (8us) between packets (quite big in my opinion). Is it possible to improve this timing?

pic_174_1.gif

regards,

gaston

0 项奖励
回复
1,708 次查看
marek_neuzil
NXP Employee
NXP Employee

Hello Gaston,

The MKE02Z derivative provide allocation of all SPI pins based on SPE bit in the SPI Control Register 1. There is not possible do disable allocation of the MOSI pin on this derivative (see the reference manual).

The delay between bytes can be caused by other interrupts routines or by the SPI interrupt routine itself. What is the bus/core clock frequency of the CPU? You can try to use higher core and bus clock frequency.

Best Regards,

Marek Neuzil

0 项奖励
回复
1,707 次查看
gschelotto
Contributor V

Hi Marek,

I'm afraid I cannot go faster as the bus/core clock is running at 16MHz. Don't worry, so far I can accept the timing between byte packets.

Again, thanks for the given support.

regards,

gaston

0 项奖励
回复