/*! * \brief Writes a byte and reads the value * \param val Value to write. This value will be shifted out * \return The value shifted in */ static uint8_t SPI_WriteRead(uint8_t val) { uint8_t ch; while (SM1_GetCharsInTxBuf()!=0) {} /* wait until tx is empty */ while (SM1_SendChar(val)!=ERR_OK) {} /* send character */ while (SM1_GetCharsInTxBuf()!=0) {} /* wait until data has been sent */ while (SM1_GetCharsInRxBuf()==0) {} /* wait until we receive data */ while (SM1_RecvChar(&ch)!=ERR_OK) {} /* get data */ return ch; }
uint8_t HardwareSPI::transfer(uint8_t val) { uint8_t ch; while(SM1_GetCharsInTxBuf()!=0) {} /* wait until tx is empty */ while(SM1_SendChar(val)!=ERR_OK) {} /* send character */ while(SM1_GetCharsInTxBuf()!=0) {} /* wait until data has been sent */ while(SM1_GetCharsInRxBuf()==0) {} /* wait until we receive data */ while(SM1_RecvChar(&ch)!=ERR_OK) {} /* get data */ return ch; }