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:
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
Solved! Go to Solution.
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
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.
What can I do to solve this?
regards,
gaston
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
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?
regards,
gaston
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
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