From e4512a2426eee6ec4c491f881ffbccd7dfd1e5a3 Mon Sep 17 00:00:00 2001 From: Yannis Chatzikonstantinou Date: Mon, 15 Apr 2024 17:24:06 +0300 Subject: [PATCH] parametrize the ssp data size --- firmware/src/sensor/amt22.c | 2 +- firmware/src/sensor/amt22.h | 7 +++++++ firmware/src/sensor/as5047.c | 2 +- firmware/src/sensor/ma7xx.c | 2 +- firmware/src/ssp/ssp_func.c | 4 ++-- firmware/src/ssp/ssp_func.h | 2 +- 6 files changed, 13 insertions(+), 6 deletions(-) diff --git a/firmware/src/sensor/amt22.c b/firmware/src/sensor/amt22.c index a62c8a2d..6a58b8ee 100644 --- a/firmware/src/sensor/amt22.c +++ b/firmware/src/sensor/amt22.c @@ -48,7 +48,7 @@ bool amt22_init_with_port(Sensor *s, const SSP_TYPE port, PAC55XX_SSP_TYPEDEF *s bool amt22_init_with_config(Sensor *s, const AMT22SensorConfig *c) { AMT22Sensor *as = (AMT22Sensor *)s; as->config = *c; - ssp_init(as->config.ssp_port, SSP_MS_MASTER, 16, 0, 0); + ssp_init(as->config.ssp_port, SSP_MS_MASTER, 16, SSP_DATA_SIZE_8, 0, 0); delay_us(10000); amt22_send_angle_cmd(s); diff --git a/firmware/src/sensor/amt22.h b/firmware/src/sensor/amt22.h index ded69dc4..86a46a48 100644 --- a/firmware/src/sensor/amt22.h +++ b/firmware/src/sensor/amt22.h @@ -66,6 +66,13 @@ static inline uint8_t amt22_get_errors(const Sensor *s) static inline void amt22_send_angle_cmd(const Sensor *s) { + // AMT22 has specific timing requirements with respect to reading + // the first and second bytes of the angle. For this reason we + // insert the 6us delay that corresponds to the datasheet-specified + // 3us + an experimentally defined value to account for transmission + // delay. + ssp_write_one(((const AMT22Sensor *)s)->config.ssp_struct, AMT22_CMD_READ_ANGLE); + delay_us(6); ssp_write_one(((const AMT22Sensor *)s)->config.ssp_struct, AMT22_CMD_READ_ANGLE); } diff --git a/firmware/src/sensor/as5047.c b/firmware/src/sensor/as5047.c index d5309792..7b8368f0 100644 --- a/firmware/src/sensor/as5047.c +++ b/firmware/src/sensor/as5047.c @@ -48,7 +48,7 @@ bool as5047p_init_with_port(Sensor *s, const SSP_TYPE port, PAC55XX_SSP_TYPEDEF bool as5047p_init_with_config(Sensor *s, const AS5047PSensorConfig *c) { AS5047PSensor *as = (AS5047PSensor *)s; as->config = *c; - ssp_init(as->config.ssp_port, SSP_MS_MASTER, 16, 1, 0); + ssp_init(as->config.ssp_port, SSP_MS_MASTER, 16, SSP_DATA_SIZE_16, 1, 0); delay_us(10000); // Example delay, adjust based on AS5047P datasheet as5047p_send_angle_cmd(s); diff --git a/firmware/src/sensor/ma7xx.c b/firmware/src/sensor/ma7xx.c index 0cc4a9f7..e86e156c 100644 --- a/firmware/src/sensor/ma7xx.c +++ b/firmware/src/sensor/ma7xx.c @@ -50,7 +50,7 @@ bool ma7xx_init_with_port(Sensor *s, const SSP_TYPE port, PAC55XX_SSP_TYPEDEF *s { MA7xxSensor *ms = (MA7xxSensor *)s; ms->config = *c; - ssp_init(ms->config.ssp_port, SSP_MS_MASTER, 4, 0, 0); + ssp_init(ms->config.ssp_port, SSP_MS_MASTER, 4, SSP_DATA_SIZE_16, 0, 0); delay_us(16000); // ensure 16ms sensor startup time as per the datasheet ma7xx_send_angle_cmd(s); ma7xx_update(s, false); diff --git a/firmware/src/ssp/ssp_func.c b/firmware/src/ssp/ssp_func.c index 72d0ed11..a1903913 100644 --- a/firmware/src/ssp/ssp_func.c +++ b/firmware/src/ssp/ssp_func.c @@ -759,7 +759,7 @@ void ssp_interrupt_disable(SSP_TYPE ssp) } } -void ssp_init(SSP_TYPE ssp, SSP_MS_TYPE ms_mode, uint8_t clkn_div, uint8_t cph, uint8_t cpol) +void ssp_init(SSP_TYPE ssp, SSP_MS_TYPE ms_mode, uint8_t clkn_div, uint32_t data_size, uint8_t cph, uint8_t cpol) { PAC55XX_SSP_TYPEDEF *ssp_ptr; @@ -804,7 +804,7 @@ void ssp_init(SSP_TYPE ssp, SSP_MS_TYPE ms_mode, uint8_t clkn_div, uint8_t cph, ssp_ptr->CON.LBM = SSP_LP_NORMAL; // Loopback Mode, no loopback mode ssp_ptr->CON.CPH = cph; // Clock Out Phase ssp_ptr->CON.CPO = cpol; // Clock Out Polarity - ssp_ptr->CON.DSS = SSP_DATA_SIZE_16; // Data Size Select, 16 bit data + ssp_ptr->CON.DSS = data_size; // Data Size Select ssp_ptr->CON.SOD = SSP_OUTPUT_NOT_DRIVE; // Slave Output Disable ssp_io_config(ssp, ms_mode); diff --git a/firmware/src/ssp/ssp_func.h b/firmware/src/ssp/ssp_func.h index 5cc80f40..df22cc7b 100644 --- a/firmware/src/ssp/ssp_func.h +++ b/firmware/src/ssp/ssp_func.h @@ -38,7 +38,7 @@ typedef enum volatile uint16_t ssp_data[10]; volatile uint16_t data_num; -extern void ssp_init(SSP_TYPE ssp, SSP_MS_TYPE ms_mode, uint8_t clkn_div, uint8_t cph, uint8_t cpol); +extern void ssp_init(SSP_TYPE ssp, SSP_MS_TYPE ms_mode, uint8_t clkn_div, uint32_t data_size, uint8_t cph, uint8_t cpol); extern void ssp_deinit(SSP_TYPE ssp); extern uint32_t ssp_write_one(PAC55XX_SSP_TYPEDEF *ssp_ptr, uint16_t data); extern uint32_t ssp_write_multi(PAC55XX_SSP_TYPEDEF *ssp_ptr, uint16_t *data, uint32_t byte_num);