![]() ![]() ![]() ![]() To read/write to a specific memory address (register), use:Ĭode: * hi2c Pointer to a I2C_HandleTypeDef structure that contains * the configuration information for the specified I2C. You must send MAX6956_Addresss, cmd and transfer/receive data, all in a single transaction. The I2C device is unselected between these calls because there was a Stop condition, so every call is a new transaction. you can't do: HAL_I2C_Master_Transmit( MAX_Addr, command) And then HAL_I2C_Master_Receive( MAX_Addr, data) And expect you'll get the data from the first command. * DevAddress Target device address: The device 7 bits address value * in datasheet must be shifted to the left before calling the interface * pData Pointer to data buffer * Size Amount of data to be sent * Timeout Timeout duration * HAL status HAL_StatusTypeDef HAL_I2C_Master_Transmit(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout) HAL_StatusTypeDef HAL_I2C_Master_Receive(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout) However, if you want to read or write to a specific register, it will fail, because it sends Start/Stops on every call. Code: /* Private variables -*/ I2C_HandleTypeDef hi2c1 UART_HandleTypeDef huart2 /* USER CODE BEGIN PV */ uint8_t devAddW = 0b10000000 // device (MAX6956) address W because end with bit 0 (write mode) uint8_t data // data array int8_t dataLength // size that has to be transmitted uint32_t tickMem // last recorded tick uint16_t delay = 200 // time delay (ms) HAL_I2C_StateTypeDef stateI2C_1 // state of the I2C bus HAL_I2C_StateTypeDef stateI2C_2 // state of the I2C bus too HAL_StatusTypeDef retI2C // value returned by I2C transmit /* USER CODE END PV */ /* Private function prototypes -*/ void SystemClock_Config(void) static void MX_GPIO_Init(void) static void MX_USART2_UART_Init(void) static void MX_I2C1_Init(void) int main(void) I also add the I2C init function so you may see if my config is wrong:Ĭode: * hi2c Pointer to a I2C_HandleTypeDef structure that contains * the configuration information for the specified I2C. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |