#include "p_i2c.h" #include "hal_i2c_m_sync.h" #include "p_usart.h" void p_i2c_init(void) { i2c_m_sync_enable(&I2C_0); } int p_i2c_write(const uint8_t* const data, uint16_t data_len) { return io_write(&I2C_0.io, data, data_len); } int p_i2c_read(uint8_t* data, uint16_t len) { return io_read(&I2C_0.io, data, len); } void p_i2c_scan(void) { PDEBUG(" "); for(int ind = 0; ind < 16; ind++) { PDEBUG(" %02x", ind); } uint8_t data = 0x00; for(int ind = 0; ind <= 119; ind++) { if (ind % 16 == 0) { PDEBUG("\r\n%02x:", ind & 0xF0); } i2c_m_sync_set_slaveaddr(&I2C_0, ind, I2C_M_SEVEN); int ret = p_i2c_write(&data, 1); if(ret != 1) { PDEBUG(" --"); } else { PDEBUG(" %02x", ind); } } PDEBUG("\r\n"); }