Hi Dale, Thank you for your reply. The Ads8638TxRx( ) function is very simple, it uses the stm32 HAL library SPI function to transmit a 16-bit word over the SPI interface (on MOSI), and at the same time it reads in 16-bit receive data (on MISO, on the other clock edge). // ADC read/write function // Sends a 16-bit command to the ADC over the SPI interface // at the same time 16-bit data is received // The ADC chip select is driven manually from a GPIO, rather than from the hardware SPI peripheral uint16_t Ads8638TxRx(uint16_t ChannelNumber) { uint16_t SpiRxData=0; WRITE_REG(ADC_CS_GPIO_Port->ODR, READ_REG(ADC_CS_GPIO_Port->ODR) & ~ADC_CS_Pin); // ADC CS pin PF6 low if(HAL_SPI_TransmitReceive(&hspi5, (uint8_t *)&ChannelNumber, (uint8_t *)&SpiRxData, 1, SPI_TIMEOUT) != HAL_OK) { Error_Handler(); } WRITE_REG(ADC_CS_GPIO_Port->ODR, READ_REG(ADC_CS_GPIO_Port->ODR) | ADC_CS_Pin); // ADC CS pin PF6 high return(SpiRxData); }; "ADC ADDRESS = 1000 hex ADC DATA = ff2 hex" is serial debug text output that I am using to test this. "ADC ADDRESS" is the top 4 bits of the data that the ADC sends back (bits 15-12) "ADC DATA" is the lower 12 bits of the data that the ADC sends back (bits 11-0) You can see this is the code snippet that I already posted: AdcData1 = Ads8638TxRx(ADS8368_SELECT_CHANNEL_1); sprintf( buffer, "ADC ADDRESS = %x hex\tADC DATA = %x hex\n", (AdcData1 & 0xf000), (AdcData1 & 0x0fff) ); HAL_UART_Transmit(&huart3, (uint8_t *)buffer, strlen(buffer), 0xFFFF); The 1st line is the SPI tx/rx command The 2nd line builds a C string that masks off the returned address and the returned data The 3rd line sends this C string over the serial UART for debugging. I will send you a timing plot tomorrow. regards, Nick
↧