Hi All,
I am using K60 Kinetis MCU in SPI Slave mode, i will be interfacing this with Microprocessor unit which acts as SPI master.
I have initialized SS1:SPI Slave_LDD using Processor Expert CPHA=1, CPHA=0 CS = ACTIVE LOW.
Attached Processor Expert file for SPI configuration reference
Slave Side
After calling the SS1_Init(NULL);
Data which i will be sending to SPI Master is sent to TXFIFO using following instruction followed by GPIO interrupt to Master
SPI2_PUSHR_SLAVE = 0x0A; |
From the debugg mode i was able to see SPI2_TXFR0 buffer filled with value 0x0A
/*Interrupt Generation to Master CPU */
GPIO2_SetFieldValue(Led1Data, INTR, 0X1); |
GPIO2_SetFieldValue(Led1Data, INTR, 0X0);
Master Side
SPI Master on receiving INTR initiates SPI read by sending dummy clock & de-asserting CS line depending on number of bytes i have to read. But i do not see any activity on MISO line and remains LOW. SPI master is configured to same CPHA & CPOL as that of slave
How do i read the data using my SPI Master from SLAVE's TX buffer? Does SPI master has to make any write before slave sends any data?
Thanks,
Sudhir
Original Attachment has been moved to: ProcessorExpert.pe.zip
Hi,
you are using SPI_Slave_LDD and you should use it's methods like SendBlock and ReceiveBlock instead writing to SPI registers. You can find example in the help of the SPISlave_LDD component using pop-up menu command "Help on component" and the go to page "Typical usage".
If you'd like to write transfer code completely by yourself, use the Init_SPI component which provides initialization only instead.
best regards
Petr Hradsky
Processor Expert Support Team
Hi Petr
I am having problem in communicating between two FRDM-K20D50M boards. I tried the code present in the help of the SPISLAVE_LDD and SPIMASTER_LDD but it didnt seem to work. then instead of 4digits I send 1 char again id didn't work. I have posted the query but still I didn't receive any helpful response Kindly look into the matter. The query is posted on the following link https://community.freescale.com/message/354381#354381.
Best Regards,
Amit Kumar
Hi,
I saw in the other thread that the problem has been in jumper on accelerometer pin.
So is the communication issue resolved now?
best regards
Petr Hradsky
Processor Expert Support Team
Hi Petr
Yes the problem is resolved as you said, the problem was on the jumper J17 present on the FRDM board. after disconnecting the track there, the SPI Communication was fine. But sometimes the sequence of the character received is changed. i.e from one side I am sending "1234" and on receiving side I am getting "1324". I guess the problem may be in transfer rate i.e on clock adjustment of SPI. How fast the data can be transmitted when connected through 10cm long wires? without any disturbance ?
Regards,
Amit Kumar
Hi,
I'm not a SPI hardware expert and this is influenced by many things. But, I would say that realistic could be around 100kHz. You can improve this by shielding (grouded at one end) and also by increasing the drive strength of the pins by decreasing pull-up values (if possible).
best regards
Petr Hradsky
Processor Expert Support Team
Thank you Petr.
I tried using the SendBlock API generated by Processor Expert code to transfer the data from Kinetis Slave, followed by GPIO interrupt to Master to read data.
SS1_SendBlock(slaveDevData, (LDD_TData*)data, 4);
/*Interrupt Generation to Master CPU */
GPIO2_SetFieldValue(Led1Data, INTR, 0X1); |
GPIO2_SetFieldValue(Led1Data, INTR, 0X0);
Both the above calls execute fine at Slave End
Problem is I am not able to read the data using my SPI master which is a different MPU not Kinetis.
Currently i initiated transfer from SPI Master by sending 4 bytes clock with CS active low, SPI mode 0 (Configured same in master & Slave) & 8MHz SPI Master Clock.
I want to know how will the master notify the slave if the data has to be read or written from slave?
Is there any requirement that master has to write a byte to slave ( Like the Register address & Set read/write bit) before SLAVE sends data on MISO lines.
In other words how can i initiate SPI transfer from Master to read data from Kinetis SPI Slave?
Thanks,
Sudhir
Hi,
On SPI the reading and writing is controlled by the same clock so basically, the master has to write any data to read the same amount of data. During writing, the data are shifted out from the register, while the incoming data are shifted in so you receive the value after the write is complete.
The slave device cannot do any sending on it's own, it's completely controlled by master's clock.
Here is example of the master code (from SPIMaster_LDD help, Typical Usage page):
...
MySPIPtr = SM1_Init(NULL); /* Initialization of SM1 component */
...
Error = SM1_ReceiveBlock(MySPIPtr, InpData, BLOCK_SIZE); /* Request data block reception */
Error = SM1_SendBlock(MySPIPtr, OutData, BLOCK_SIZE); /* Start transmission/reception */
while (!DataReceivedFlag) {}; // wait until the data are received
...
best regards
Petr Hradsky
Processor Expert Support Team