 
					
				
		
Hello,
I tested spi interface with maxim device from MKL34Z64.
But I can't understand this issue.
Why that is only six clock of SCK?
Also, I send each 3 bytes, but only the same value is output continuously.
I use driver of fsl_spi.c (SPI_WriteData)
I attached project file.
Would you please let me know why occurred like this situation?
I must need to solve this problem.
thanks.
Original Attachment has been moved to: WIZIT_Flowmeter.zip
Solved! Go to Solution.
 
					
				
		
 Hui_Ma
		
			Hui_Ma
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		Hi
I had tested with FRDM-KL43Z board with SPI1 and FIFO mode enabled.
The KL34 SPI supports up to 8-byte-deep FIFO, so customer could call SPI_WriteData() to transmit data up to 8 times.
While, after customer call SPI_WriteData() function, it need to polling the SPIx_S[SPTEF] bit to make sure the SPI transmit Buffer(FIFO) empty.
When the SPI FIFO enabled, I could call below code to send 8 bytes out:
    SPI_WriteData(SPI1, 0x18);
    SPI_WriteData(SPI1, 0x28);
    SPI_WriteData(SPI1, 0x38);
    SPI_WriteData(SPI1, 0x48);
    SPI_WriteData(SPI1, 0x58);
    SPI_WriteData(SPI1, 0x68);
    SPI_WriteData(SPI1, 0x78);
    SPI_WriteData(SPI1, 0x88);
    while(!(SPI1->S &  SPI_S_SPTEF_MASK))
    {}
I attached my test code for your reference.
When the SPI FIFO enabled, there doesn't need add delay() function between SPI_WriteData() function.
Wish it helps.
Have a great day,
Ma Hui
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
 
					
				
		
 Hui_Ma
		
			Hui_Ma
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		Hi
I checked your code, below code should be incorrect:
    SPI_WriteData(SPI1, (char)0x38);
    SPI_WriteData(SPI1, (char)0x13);
    SPI_WriteData(SPI1, (char)0x11);
There should wait previous SPI_WriteData() finished before call the next SPI_WriteData().
Please refer KSDK provided SPI example code, there call the SPI_WriteData() function in interrupt service routine:
void SPI_MASTER_IRQHandler(void)
{
    if (SPI_GetStatusFlags(EXAMPLE_SPI_MASTER) & kSPI_TxBufferEmptyFlag)
    {
        SPI_WriteData(EXAMPLE_SPI_MASTER, (uint16_t)(srcBuff[BUFFER_SIZE - masterIndex]));
        masterIndex--;
    }
    if (masterIndex == 0U)
    {
        masterFinished = true;
        SPI_DisableInterrupts(EXAMPLE_SPI_MASTER, kSPI_TxEmptyInterruptEnable);
    }
}
The SPI interrupt example could be found in below found:
..\SDK_2.0_FRDM-KL43Z\boards\frdmkl43z\driver_examples\spi\interrupt
Wish it helps.
Have a great day,
Ma Hui
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
 
					
				
		
Dear Hui_Ma,
Thank you for your support.
But I don't want to use an interrupt.
If i use a delay function, Is it ok?
SPI_WriteData(SPI1, (char)0x38);delay(10);
SPI_WriteData(SPI1, (char)0x13);delay(10);
SPI_WriteData(SPI1, (char)0x11);delay(10);
And I still don't understand spi waveform.(spi clk)
Thanks.
Best Regards,
JT Park
 
					
				
		
 Hui_Ma
		
			Hui_Ma
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		Hi
I had tested with FRDM-KL43Z board with SPI1 and FIFO mode enabled.
The KL34 SPI supports up to 8-byte-deep FIFO, so customer could call SPI_WriteData() to transmit data up to 8 times.
While, after customer call SPI_WriteData() function, it need to polling the SPIx_S[SPTEF] bit to make sure the SPI transmit Buffer(FIFO) empty.
When the SPI FIFO enabled, I could call below code to send 8 bytes out:
    SPI_WriteData(SPI1, 0x18);
    SPI_WriteData(SPI1, 0x28);
    SPI_WriteData(SPI1, 0x38);
    SPI_WriteData(SPI1, 0x48);
    SPI_WriteData(SPI1, 0x58);
    SPI_WriteData(SPI1, 0x68);
    SPI_WriteData(SPI1, 0x78);
    SPI_WriteData(SPI1, 0x88);
    while(!(SPI1->S &  SPI_S_SPTEF_MASK))
    {}
I attached my test code for your reference.
When the SPI FIFO enabled, there doesn't need add delay() function between SPI_WriteData() function.
Wish it helps.
Have a great day,
Ma Hui
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
 
					
				
		
Dear Hui_Ma,
Thank you for your reply.
I solved it.(I used SPI_WriteBlocking fuction.)
 srcBuff[0] = 0x38;
 srcBuff[1] = 0x13;
 srcBuff[2] = 0x11;
 
 SPI_WriteBlocking( SPI1, srcBuff, 3 );
 
I tested read function of SPI interface but it didn't work.
I used SPI_ReadData function of fsl_spi.c.
Would you please provide to me example code of read function?
Thanks.
 
					
				
		
 Hui_Ma
		
			Hui_Ma
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		Hi
For the SPI communication is TX/RX synchronize, when you need read SPI data, the SPI master need to transmit the dummy data at first. After that,then call SPI_ReadData() function to read received data.
Wish it helps.
Have a great day,
Ma Hui
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
