Ryo Od
/
Nucleo_i2c_master_writer
I2C Master Test
main.cpp@0:4f748e5902b7, 2018-11-04 (annotated)
- Committer:
- ryood
- Date:
- Sun Nov 04 09:02:48 2018 +0000
- Revision:
- 0:4f748e5902b7
first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ryood | 0:4f748e5902b7 | 1 | #include "mbed.h" |
ryood | 0:4f748e5902b7 | 2 | |
ryood | 0:4f748e5902b7 | 3 | #define I2C_ARDUINO_ADDR (0x08 << 1) // 8bit address |
ryood | 0:4f748e5902b7 | 4 | |
ryood | 0:4f748e5902b7 | 5 | I2C I2cArduino(PB_9, PB_8); // SDA, SCL |
ryood | 0:4f748e5902b7 | 6 | |
ryood | 0:4f748e5902b7 | 7 | int main() |
ryood | 0:4f748e5902b7 | 8 | { |
ryood | 0:4f748e5902b7 | 9 | I2cArduino.frequency(400000); |
ryood | 0:4f748e5902b7 | 10 | |
ryood | 0:4f748e5902b7 | 11 | uint8_t x = 0; |
ryood | 0:4f748e5902b7 | 12 | while(1) { |
ryood | 0:4f748e5902b7 | 13 | if (I2cArduino.write(I2C_ARDUINO_ADDR, "x is ", 5, true) != 0) { |
ryood | 0:4f748e5902b7 | 14 | printf("I2C failure"); |
ryood | 0:4f748e5902b7 | 15 | } |
ryood | 0:4f748e5902b7 | 16 | if (I2cArduino.write(I2C_ARDUINO_ADDR, (char *)&x, 1) != 0) { |
ryood | 0:4f748e5902b7 | 17 | printf("I2C failure"); |
ryood | 0:4f748e5902b7 | 18 | } |
ryood | 0:4f748e5902b7 | 19 | x++; |
ryood | 0:4f748e5902b7 | 20 | wait_ms(500); |
ryood | 0:4f748e5902b7 | 21 | } |
ryood | 0:4f748e5902b7 | 22 | } |