mirror of https://github.com/ARMmbed/mbed-os.git
Fix dropped bytes on spi write
The cyhal_spi_send api was changed to read and discard a byte on every send operation (at the protocol level all SPI transfers are bidirectional). This means that to achieve a truly bidirectional transfer, the cyhal_spi_transfer API must be called (as opposed to a write followed by a read).pull/11894/head
parent
82ecd19e9c
commit
61218d00ea
|
@ -130,12 +130,11 @@ void spi_frequency(spi_t *obj, int hz)
|
|||
int spi_master_write(spi_t *obj, int value)
|
||||
{
|
||||
struct spi_s *spi = cy_get_spi(obj);
|
||||
uint32_t received;
|
||||
if (CY_RSLT_SUCCESS != cyhal_spi_send(&(spi->hal_spi), (uint32_t)value)) {
|
||||
MBED_ERROR(MBED_MAKE_ERROR(MBED_MODULE_DRIVER_SPI, MBED_ERROR_CODE_FAILED_OPERATION), "cyhal_spi_send");
|
||||
}
|
||||
if (CY_RSLT_SUCCESS != cyhal_spi_recv(&(spi->hal_spi), &received)) {
|
||||
MBED_ERROR(MBED_MAKE_ERROR(MBED_MODULE_DRIVER_SPI, MBED_ERROR_CODE_FAILED_OPERATION), "cyhal_spi_recv");
|
||||
uint8_t received;
|
||||
uint8_t value_byte = (uint8_t)value;
|
||||
|
||||
if (CY_RSLT_SUCCESS != cyhal_spi_transfer(&(spi->hal_spi), &value_byte, 1, &received, 1, 0xff)) {
|
||||
MBED_ERROR(MBED_MAKE_ERROR(MBED_MODULE_DRIVER_SPI, MBED_ERROR_CODE_FAILED_OPERATION), "cyhal_spi_transfer");
|
||||
}
|
||||
return (int)received;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue