Jaroslav Cermak

SPI with DMA, KL16Z128, Procesor expert

Discussion created by Jaroslav Cermak on Dec 14, 2016

Hi All,

 

I am using processor KL16Z128 and KDS3.2 + PEx.
Because of speed and absence of SPI's input buffer I need to use SPI with DMA. If I set SPI parameters according to print screens attached below then every sent frame repeats its first byte (an extra byte is sent). How do I remove this extra byte? I found similar problem in discussion. It was solved with writing to register
SPI1_C3 = 0x01. I have to use SPI0 and SPI0 does not have this register. If I allow trigger on RxDMA then I can see repeated byte only in first frame but I do not receive any data! Does anybody knows how to solve this problem? 

 

LDD_TDeviceData *TimerData; // triggerTimer
LDD_TDeviceData *MySPIEthPtr; // SPI ETH W5200

 

TimerData = TU1_Init(NULL); // trigger Timer 40us
MySPIEthPtr = SpiETH_Init(NULL); // Spi pro W5200 ETH

w5200_spi_comm_buff[0] = 0x00;
w5200_spi_comm_buff[1] = 0x00;
// OP code + length
w5200_spi_comm_buff[2] = 0x80;
w5200_spi_comm_buff[3] = 19;
// mode registr = 0x00
w5200_spi_comm_buff[4] = 0x00;
// gateway
w5200_spi_comm_buff[5] = w5200_init_conf_params_ptr->gateway_addr[0];
w5200_spi_comm_buff[6] = w5200_init_conf_params_ptr->gateway_addr[1];
w5200_spi_comm_buff[7] = w5200_init_conf_params_ptr->gateway_addr[2];
w5200_spi_comm_buff[8] = w5200_init_conf_params_ptr->gateway_addr[3];
// subnet mask
w5200_spi_comm_buff[9] = w5200_init_conf_params_ptr->subnet_mask[0];
w5200_spi_comm_buff[10] = w5200_init_conf_params_ptr->subnet_mask[1];
w5200_spi_comm_buff[11] = w5200_init_conf_params_ptr->subnet_mask[2];
w5200_spi_comm_buff[12] = w5200_init_conf_params_ptr->subnet_mask[3];
// MAC adresa
w5200_spi_comm_buff[13] = w5200_init_conf_params_ptr->mac_addr[0];
w5200_spi_comm_buff[14] = w5200_init_conf_params_ptr->mac_addr[1];
w5200_spi_comm_buff[15] = w5200_init_conf_params_ptr->mac_addr[2];
w5200_spi_comm_buff[16] = w5200_init_conf_params_ptr->mac_addr[3];
w5200_spi_comm_buff[17] = w5200_init_conf_params_ptr->mac_addr[4];
w5200_spi_comm_buff[18] = w5200_init_conf_params_ptr->mac_addr[5];
// Source IP address
w5200_spi_comm_buff[19] = w5200_init_conf_params_ptr->source_ip_addr[0];
w5200_spi_comm_buff[20] = w5200_init_conf_params_ptr->source_ip_addr[1];
w5200_spi_comm_buff[21] = w5200_init_conf_params_ptr->source_ip_addr[2];
w5200_spi_comm_buff[22] = w5200_init_conf_params_ptr->source_ip_addr[3];
//
SpiETH_ReceiveBlock(MySPIEthPtr, data_buff_tmp, 23);
SpiETH_SendBlock(MySPIEthPtr, w5200_spi_comm_buff, 23);         // Send

while(!SpiETH_GetBlockSentStatus(MySPIEthPtr))                              // Check receive
{}


w5200_spi_comm_buff[0] = 0x00;
w5200_spi_comm_buff[1] = 0x00;
// OP code + length
w5200_spi_comm_buff[2] = 0x00;
w5200_spi_comm_buff[3] = 19;

DataReceivedSpiEthFlag = 0;
SpiETH_ReceiveBlock(MySPIEthPtr, data_buff_tmp, 23);
SpiETH_SendBlock(MySPIEthPtr, w5200_spi_comm_buff, 23);         // Send


while(!SpiETH_GetBlockReceivedStatus(MySPIEthPtr))                     // Check receive
{}

 

 

Without the trigger on Rx / Tx I do not receive data.

 

Thanks.

Attachments

Outcomes