I am implementing an I2C slave in c with PIGPIO and I have run into a snag. I want to send numbers. The struct is
typedef struct
{
uint32_t control; /* Write */
int rxCnt; /* Read only */
char rxBuf[BSC_FIFO_SIZE]; /* Read only */
int txCnt; /* Write */
char txBuf[BSC_FIFO_SIZE]; /* Write */
} bsc_xfer_t;
I can send data to the slave as unsigned char array and it is working fine. However the data coming back from the PI is variable and incorrect. I have done some more testing on the PI to confirm the data is correctly added to the buffer. However that was not extensive I will do more.
I think I have nailed it down to the txBuf in the struct being unsigned.
All the Arduino stuff is using uin8_t
(unsigned char
).
On my Arduinos I have just been using a union to do simple conversions
typedef union {
uint8_t bytes[4];
uint32_t number;
} _UINT32;
Reading in the values work cleanly but sending them back doesn't.
Has anyone got any ideas how to deal with this?