I am using stm32f2 series as master to access data from TMP126.
SPI configuration:
Full duplex master mode
mode: CPOL=0 CPAHASE=0 (mode 0)
data size=8bit
First bit= MSB
when i read single register first time after dumping or restarting it will give exact default values.
when i read in the while loop continuously it will read first iteration default values afterwards it will give the garbage values.
1) i tried with Repeated Data Read from a Single Register frame format =0x03 0x0C
1st iteration reading 0x2126 after that garbage values
2) i tried with Burst Data Read from Multiple Registers =0x03 0x00 to till 07h register
1st read 0 to 07 h reads correctly
after that garbage values are occurring.
https://postimg.cc/gallery/tj1Nywj
but in both case 1 iteration it will read the default values afterwards unknown values will be read.
My code snippet
void tmp_get8bit(uint8_t *txbuff,uint8_t *rxbuff,int size)
{
uint8_t chrxbuff[size];
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_RESET);
HAL_Delay(5); //milisec
HAL_SPI_TransmitReceive(&hspi3, txbuff, chrxbuff, size, 500);
HAL_Delay(5);//milisec
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_SET);
rxbuff[0]=chrxbuff[2];
rxbuff[1]=chrxbuff[3];
}
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_SPI3_Init();
uint8_t txbuff[18]={0x03,0x0C};
while (1)
{
uint8_t rxbuff[2];
MX_SPI3_Init();
tmp_get8bit(txbuff,rxbuff,6);
}
}
static void MX_SPI3_Init(void)
{
/* USER CODE BEGIN SPI3_Init 0 */
/* USER CODE END SPI3_Init 0 */
/* USER CODE BEGIN SPI3_Init 1 */
/* USER CODE END SPI3_Init 1 */
/* SPI3 parameter configuration*/
hspi3.Instance = SPI3;
hspi3.Init.Mode = SPI_MODE_MASTER;
hspi3.Init.Direction = SPI_DIRECTION_2LINES;
hspi3.Init.DataSize = SPI_DATASIZE_8BIT;
hspi3.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi3.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi3.Init.NSS = SPI_NSS_SOFT;
hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64;
hspi3.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi3.Init.TIMode = SPI_TIMODE_DISABLE;
hspi3.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi3.Init.CRCPolynomial = 10;
if (HAL_SPI_Init(&hspi3) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN SPI3_Init 2 */
/* USER CODE END SPI3_Init 2 */
}
Regards,
Sandeep C