2023-04-05 08:37 AM - edited 2023-11-20 08:53 AM
Hi everyone,
I am using the NUCLEO STM32-F401RE V dev board and trying to communicate with an MAX31856 temperature amplifier. I am using SPI2 peripheral. I am able to write values on the SPI line. I have printed them out to the UART and have verified the signal with the scope. However, I am having trouble reading the MAX chip. For this I am using the HAL_SPI_TransmitReceive() function. After a lot of debugging, I have narrowed down to just trying to read the values I am writing to CR0, CR1, and Mask registers. I have verified the writes with the scope but don't see anything on the SDO from the MAX chip when I attempt to read the registers. I've done a loopback test and measure the data I am writing from the MOSI on the MISO of the STM32 which tells me my SPI is configured correctly. I don't see anything on the MAX and I've tried I've tried 3 different chips at this point and they all have the same behavior so I believe there is something wrong with my code. I have attached some code snippets and screenshots of the scope data. I was wondering if there is something in the configuration of the chip that I am missing? all I am doing is Setting
CR0 to 0X80
CR1 to 0X03
MASK to 0X00
max31856_write_register(MAX31856_CRO_WRITE_REG, 0x80); // Enable automatic conversion mode
max31856_write_register(MAX31856_CR1_WRITE_REG, 0x03); // Set thermocouple type to K-type (default)
max31856_write_register(MAX31856_MASK_WRITE_REG, 0x00); // Disable all fault mask settings
and attempting to read them back:
uint8_t readCR_0 = max31856_read_register(MAX31856_CR0_READ_REG);
sprintf(Readbuffer, "Read CR_0: 0x%02X\r\n", readCR_0);
HAL_UART_Transmit(&huart2, (uint8_t *)Readbuffer, strlen(Readbuffer), 100);
any help is very appreciated.
My CPOL is low
CPHA is edge 1
and I have the prescaler at 32, Which is in range of the max chip per the datasheet.
Serial Data output of the CR0 read and write
Yellow is CLK
Blue is MOSI of STM32 to SDI of MAX31856
Function calls referenced above:
uint8_t max31856_read_register(uint8_t reg) {
int SPI_Comerror;
uint8_t tx_buffer[2] = {reg , reg}; //CR0 read reg = 0X00
uint8_t rx_buffer[2];
// Transmit the register address
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET);
HAL_Delay(10);
SPI_Comerror = HAL_SPI_TransmitReceive(&hspi2, tx_buffer, rx_buffer, 2, 100);
if (SPI_Comerror != HAL_OK) {
HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET);
}
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET);
HAL_Delay(10);
return rx_buffer[1];
}
uint8_t max31856_write_register(uint8_t reg, uint8_t data) {
int SPI_Comerror;
uint8_t buffer[2] = {reg, data}; // CR0 reg addr = 0x80
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET);
HAL_Delay(10);
SPI_Comerror = HAL_SPI_Transmit(&hspi2, buffer, 2, 100);
if( SPI_Comerror != HAL_OK){
HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET);
}
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET);
HAL_Delay(10);
return buffer[1];
}
#STM32CubeIDE #SPI
2023-12-24 07:44 PM
@RPisa.1, were you able to resolve this?
I have seen some rumors about nCS glitches which can affect the MAX31856.