Skip to content

Commit 1b14120

Browse files
committed
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).
1 parent 1798c24 commit 1b14120

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

targets/TARGET_Cypress/TARGET_PSOC6/cy_spi_api.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,11 @@ void spi_frequency(spi_t *obj, int hz)
130130
int spi_master_write(spi_t *obj, int value)
131131
{
132132
struct spi_s *spi = cy_get_spi(obj);
133-
uint32_t received;
134-
if (CY_RSLT_SUCCESS != cyhal_spi_send(&(spi->hal_spi), (uint32_t)value)) {
135-
MBED_ERROR(MBED_MAKE_ERROR(MBED_MODULE_DRIVER_SPI, MBED_ERROR_CODE_FAILED_OPERATION), "cyhal_spi_send");
136-
}
137-
if (CY_RSLT_SUCCESS != cyhal_spi_recv(&(spi->hal_spi), &received)) {
138-
MBED_ERROR(MBED_MAKE_ERROR(MBED_MODULE_DRIVER_SPI, MBED_ERROR_CODE_FAILED_OPERATION), "cyhal_spi_recv");
133+
uint8_t received;
134+
uint8_t value_byte = (uint8_t)value;
135+
136+
if (CY_RSLT_SUCCESS != cyhal_spi_transfer(&(spi->hal_spi), &value_byte, 1, &received, 1, 0xff)) {
137+
MBED_ERROR(MBED_MAKE_ERROR(MBED_MODULE_DRIVER_SPI, MBED_ERROR_CODE_FAILED_OPERATION), "cyhal_spi_transfer");
139138
}
140139
return (int)received;
141140
}

0 commit comments

Comments
 (0)