i2c.h 938 B

1234567891011121314151617181920212223242526272829303132333435
  1. #pragma once
  2. #ifndef I2C_H
  3. #define I2C_H
  4. #include "stm8s.h"
  5. #define I2C_FAST 1
  6. #define F_MASTER_MHZ 16UL
  7. #define F_MASTER_HZ 16000000UL
  8. #ifdef I2C_FAST
  9. //400 кГц
  10. #define F_I2C_HZ 400000UL
  11. #else
  12. //100 кГц
  13. #define F_I2C_HZ 100000UL
  14. #endif // I2C_FAST
  15. //Результат выполнения операции с i2c
  16. typedef enum {
  17. I2C_SUCCESS = 0,
  18. I2C_TIMEOUT,
  19. I2C_ERROR
  20. } t_i2c_status;
  21. // Инициализация I2C интерфейса
  22. extern void i2c_master_init(void);
  23. // Запись регистра slave-устройства
  24. extern t_i2c_status i2c_wr_reg(uint8_t address, uint8_t reg_addr, \
  25. const uint8_t * data, uint8_t length);
  26. // Чтение регистра slave-устройства
  27. extern t_i2c_status i2c_rd_reg(uint8_t address, uint8_t reg_addr, \
  28. uint8_t * data, uint8_t length);
  29. #endif // I2C_H