Skip to content

Commit ad09a83

Browse files
committed
NUCLEO R030R8 16Bit SPI read and write
add 16 bit read and write
1 parent 3d72f3d commit ad09a83

File tree

1 file changed

+17
-5
lines changed
  • libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8

1 file changed

+17
-5
lines changed

libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/spi_api.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,19 @@ static inline int ssp_writeable(spi_t *obj) {
215215
static inline void ssp_write(spi_t *obj, int value) {
216216
SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
217217
while (!ssp_writeable(obj));
218-
SPI_SendData8(spi, (uint8_t)value);
218+
if(obj->bits == SPI_DATASIZE_8BIT) // 8 bit mode
219+
SPI_SendData8(spi, (uint8_t)value);
220+
else
221+
SPI_I2S_SendData16(spi, (uint16_t)value);
219222
}
220223

221224
static inline int ssp_read(spi_t *obj) {
222225
SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
223226
while (!ssp_readable(obj));
224-
return (int)SPI_ReceiveData8(spi);
227+
if(obj->bits == SPI_DATASIZE_8BIT) // 8 bit mode
228+
return (int)SPI_ReceiveData8(spi);
229+
else // 16 bit mode
230+
return (int)SPI_I2S_ReceiveData16(spi);
225231
}
226232

227233
static inline int ssp_busy(spi_t *obj) {
@@ -242,13 +248,19 @@ int spi_slave_receive(spi_t *obj) {
242248

243249
int spi_slave_read(spi_t *obj) {
244250
SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
245-
return (int)SPI_ReceiveData8(spi);
251+
if(obj->bits == SPI_DATASIZE_8BIT) // 8 bit mode
252+
return (int)SPI_ReceiveData8(spi);
253+
else
254+
return (int)SPI_I2S_ReceiveData16(spi);
246255
}
247256

248257
void spi_slave_write(spi_t *obj, int value) {
249258
SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
250-
while (!ssp_writeable(obj));
251-
SPI_SendData8(spi, (uint8_t)value);
259+
while (!ssp_writeable(obj));
260+
if(obj->bits == SPI_DATASIZE_8BIT) // 8 bit mode
261+
SPI_SendData8(spi, (uint8_t)value);
262+
else
263+
SPI_I2S_SendData16(spi, (uint16_t)value);
252264
}
253265

254266
int spi_busy(spi_t *obj) {

0 commit comments

Comments
 (0)