Hi Ryan, Thanks for replying to my post. I will implement that a bit later as I don't have low value fixed resistors at the moment. Right now I am facing another issue. When I read the ID, I am also getting the CONFIG1 register which is the register right after the ID, even though I set the RREG command to {0x20 | 0x00, 0x00}, indicating that I only want to read one byte. Do you have any suggestions on how to get rid of the extra byte? I thought I was flushing the FIFO by reading the buffer after each byte that was sent. void ADS1298_ReadConfig1 ( SPI_HandleTypeDef * hspi ) { uint8_t command [ 2 ] = { 0x20 | 0x00 , 0x00 } ; // RREG command for sending ID uint8_t sdatacCmd = 0x11 ; // SDATAC mode command for sending data GPIOA -> BSRR = GPIO_BSRR_BR4 ; // CS LOW * ( volatile uint8_t * ) & SPI1 -> DR = sdatacCmd ; // SDATAC command, stop reading data so the ADS1298 can receive commands -- direct register access method while ( ! ( SPI1 -> SR & SPI_SR_TXE )) ; // Wait until TXE (Transmit buffer empty) is set while ( SPI1 -> SR & SPI_SR_BSY ) ; // Wait for transmission to complete while ( ! ( SPI1 -> SR & SPI_SR_RXNE )) ; // Wait until RXNE (Receive buffer empty) is set volatile uint8_t sdatac_status = * ( volatile uint8_t * ) & SPI1 -> DR ; // Discard * ( volatile uint8_t * ) & SPI1 -> DR = command [ 0 ] ; while ( ! ( SPI1 -> SR & SPI_SR_TXE )) ; while ( SPI1 -> SR & SPI_SR_BSY ) ; while ( ! ( SPI1 -> SR & SPI_SR_RXNE )) ; volatile uint8_t rreg_status1 = * ( volatile uint8_t * ) & SPI1 -> DR ; // Discard * ( volatile uint8_t * ) & SPI1 -> DR = command [ 1 ] ; while ( ! ( SPI1 -> SR & SPI_SR_TXE )) ; while ( SPI1 -> SR & SPI_SR_BSY ) ; while ( ! ( SPI1 -> SR & SPI_SR_RXNE )) ; volatile uint8_t rreg_status2 = * ( volatile uint8_t * ) & SPI1 -> DR ; // Discard * ( volatile uint8_t * ) & SPI1 -> DR = 0xFF ; // Dummy byte while ( ! ( SPI1 -> SR & SPI_SR_TXE )) ; while ( SPI1 -> SR & SPI_SR_BSY ) ; while ( ! ( SPI1 -> SR & SPI_SR_RXNE )) ; response = * ( volatile uint8_t * ) & SPI1 -> DR ; // Save ID in a buffer for ( int i = 0 ; i 2 us between last CLK falling edge and CS high GPIOA -> BSRR = GPIO_BSRR_BS4 ; // CS HIGH printf ( "CONFIG1: 0x%02X\n" , response ) ; }
↧