This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TPS92518:Change the SPI clock parameters, the READ value is not coming out correctly

Part Number: TPS92518

Tool/software:

Hello.

I need the help of experts.

The READ value works correctly when the TPS92518 is configured with the settings below.

However, when I increase the baud rate, the READ value does not work correctly. Could you help identify the cause?

uint16_t tps_act_regi[7]={CONTROL,LED1_PKTH_DAC,LED2_PKTH_DAC,LED1_TOFF_DAC,
			LED2_TOFF_DAC,LED1_MAXOFF_DAC,LED2_MAXOFF_DAC} ;
			
void WnR_AssembleSPICmd(void)
{
	
	for(int i = 0; i<sizeof(tps_act_regi) / sizeof(tps_act_regi[0]) ; i++)
	{
		W_AssembleSPICmd[i]= AssembleSPICmd(1, tps_act_regi[i],tps92518_initValues[i]);

	}

	for(int i = 0; i<sizeof(tps_act_regi) / sizeof(tps_act_regi[0]) ; i++)
	{
		R_AssembleSPICmd[i]= AssembleSPICmd(0, tps_act_regi[i],tps92518_initValues[i]);

	}
}

void spi_tps_For_Read(uint16_t AssembleSPICmd)
{

	uint16_t ReadAssemble= AssembleSPICmd;
	uint16_t rx_RValue;

	HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
	while(HAL_GPIO_ReadPin(GPIOD, GPIO_PIN_2)!=GPIO_PIN_RESET){};
	HAL_SPI_Receive_DMA(&hspi3, (uint8_t*)&rx_RValue, sizeof(rx_RValue));
	HAL_SPI_Transmit_DMA(&hspi3, (uint8_t*)&ReadAssemble, sizeof(ReadAssemble));
	while (HAL_SPI_GetState(&hspi3) != HAL_SPI_STATE_READY) {}
	
	HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
	Translate_spi(rx_RValue);
}

void spi_tps_For_Write(uint16_t AssembleSPICmd)
{
	uint16_t WriteAssemble= AssembleSPICmd;
	uint16_t rx_WValue;

	HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET); 
	
	while(HAL_GPIO_ReadPin(GPIOD, GPIO_PIN_2)!=GPIO_PIN_RESET){};
	HAL_SPI_Receive_DMA(&hspi3, (uint8_t*)&rx_WValue, sizeof(rx_WValue));
	HAL_SPI_Transmit_DMA(&hspi3, (uint8_t*)&WriteAssemble, sizeof(WriteAssemble));
	while (HAL_SPI_GetState(&hspi3) != HAL_SPI_STATE_READY) {}

	HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);

	Translate_spi_for_Read(rx_WValue);
}
void Translate_spi(uint16_t Receive_DMA)
{
#if 1
	uint16_t rx_1 = Receive_DMA ;

	#define SPE_MASK      0x8000
	#define CMD_MASK      0x4000
	#define ADDRESS_MASK  0x3E00
	#define DATA_MASK     0x01FF

	uint16_t address = (rx_1 & ADDRESS_MASK) >> 9;
	uint16_t data = rx_1 & DATA_MASK;

	switch(address)
	{
		case 0: Printf("INF:      control     "); break;
		case 1: Printf("INF:      status      "); break;
		case 2: Printf("INF:  therm_warn_Lmt  "); break;
		case 3: Printf("INF:   Led1_pkth_dac  "); break;
		case 4: Printf("INF:   Led2_pkth_dac  "); break;
		case 5: Printf("INF:   Led1_toff_dac  "); break;
		case 6: Printf("INF:   Led2_toff_dac  "); break;
		case 7: Printf("INF:  Led1_maxoff_dac "); break;
		case 8: Printf("INF:  Led2_maxoff_dac "); break;
		case 9: Printf("INF:      Vtherm      "); break;
		case 10: Printf("INF: Led1_most_recent"); break;
		case 11: Printf("INF:  Led1_last_on   "); break;
		case 12: Printf("INF:  Led1_last_off  "); break;
		case 13: Printf("INF: Led2_most_rescent");break;
		case 14: Printf("INF:  Led2_last_on   "); break;
		case 15: Printf("INF:  Led2_last_off  "); break;
		case 16: Printf("INF:       Reset     "); break;
		default: Printf("INF:       Read      "); break;
	}
	if(address == 0)
	{
		switch(data)
		{
		case 28: Printf(": <Ch1 Ch2> Turn Off\r\n");break;
		case 29: Printf(": <Ch1> On <Ch2> Off\r\n");break;
		case 30: Printf(": <Ch1> Off <Ch2> On\r\n");break;
		case 31: Printf(": <Ch1 Ch2> Turn On\r\n");break;
		}
	}
	else{ Printf(": %u\r\n", data); }
#endif
}

void PKTHC_Control(int channel, uint16_t Pkthc)
{
    int Sequence;

    if(channel == 0)
    {
        Sequence = 1;
        tps92518_initValues[1] = Pkthc;

        WnR_AssembleSPICmd();
        spi_tps_For_Write(W_AssembleSPICmd[Sequence]);
        spi_tps_For_Read(R_AssembleSPICmd[Sequence]);
    }
    else if(channel == 1)
    {
        Sequence = 2;
        tps92518_initValues[2] = Pkthc;
        WnR_AssembleSPICmd();
        spi_tps_For_Write(W_AssembleSPICmd[Sequence]);
        spi_tps_For_Read(R_AssembleSPICmd[Sequence]);
    }
    else ;
}

The READ value does not work correctly at prescaler values of 8 (5.25 MBits/s), 4 (10.5 MBits/s), and 2 (21.0 MBits/s). However, the WRITE function still works fine.