Marek Trojan
/
_8_KL46_M_simple_write
program for I2C master device
Fork of I2C_HelloWorld_Mbed by
main.h@9:36fc715eb54c, 2015-12-17 (annotated)
- Committer:
- marcus255
- Date:
- Thu Dec 17 23:04:29 2015 +0000
- Revision:
- 9:36fc715eb54c
- Parent:
- 8:3e6945d5d9a1
- Child:
- 10:39dd1d3508c3
I2C device selected by pushbuttons, sequential memory read, writting random data sequentially (works, but some troubles with addressing occurs)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
marcus255 | 4:1ec553356dcc | 1 | #ifndef MAIN_H |
marcus255 | 4:1ec553356dcc | 2 | #define MAIN_H |
marcus255 | 4:1ec553356dcc | 3 | |
marcus255 | 4:1ec553356dcc | 4 | #include "mbed.h" |
marcus255 | 4:1ec553356dcc | 5 | #define SLAVE_ADDR 0xA0 |
marcus255 | 7:b07706b16279 | 6 | #define DATA_SIZE 16 |
marcus255 | 8:3e6945d5d9a1 | 7 | #define RTC_ADDR 0xD0 |
marcus255 | 8:3e6945d5d9a1 | 8 | #define TEMPERATURE_REGISTER 0x11 |
marcus255 | 9:36fc715eb54c | 9 | #define RIGHT_PUSH_BUTTON PTC3 |
marcus255 | 9:36fc715eb54c | 10 | #define LEFT_PUSH_BUTTON PTC12 |
marcus255 | 4:1ec553356dcc | 11 | |
marcus255 | 9:36fc715eb54c | 12 | #define SENSOR_ROUTINE 1 |
marcus255 | 9:36fc715eb54c | 13 | #define MEMORY_ROUTINE 2 |
marcus255 | 9:36fc715eb54c | 14 | |
marcus255 | 9:36fc715eb54c | 15 | InterruptIn left_but(LEFT_PUSH_BUTTON); |
marcus255 | 9:36fc715eb54c | 16 | InterruptIn right_but(RIGHT_PUSH_BUTTON); |
marcus255 | 4:1ec553356dcc | 17 | I2C i2c(PTE0, PTE1); |
marcus255 | 4:1ec553356dcc | 18 | Serial pc(USBTX, USBRX); |
marcus255 | 4:1ec553356dcc | 19 | DigitalOut led(LED_GREEN); |
marcus255 | 4:1ec553356dcc | 20 | Ticker i2c_ticker; |
marcus255 | 5:8dc6d7d81250 | 21 | void write_data(void); |
marcus255 | 7:b07706b16279 | 22 | void read_data(char*); |
marcus255 | 5:8dc6d7d81250 | 23 | void write_and_read(void); |
marcus255 | 9:36fc715eb54c | 24 | void memory_routine(void); |
marcus255 | 9:36fc715eb54c | 25 | void sensor_routine(void); |
marcus255 | 8:3e6945d5d9a1 | 26 | |
marcus255 | 8:3e6945d5d9a1 | 27 | void rtc_sensor(); |
marcus255 | 9:36fc715eb54c | 28 | int get_temperature_raw(char*); |
marcus255 | 8:3e6945d5d9a1 | 29 | float proceed_temperature(char*); |
marcus255 | 8:3e6945d5d9a1 | 30 | |
marcus255 | 9:36fc715eb54c | 31 | unsigned int rnd(void); |
marcus255 | 9:36fc715eb54c | 32 | int routine; |
marcus255 | 9:36fc715eb54c | 33 | char memory_cell_addr; |
marcus255 | 9:36fc715eb54c | 34 | unsigned int m_z; |
marcus255 | 9:36fc715eb54c | 35 | unsigned int m_w; |
marcus255 | 9:36fc715eb54c | 36 | |
marcus255 | 4:1ec553356dcc | 37 | void init(void); |
marcus255 | 9:36fc715eb54c | 38 | char data[DATA_SIZE + 1]; |
marcus255 | 9:36fc715eb54c | 39 | |
marcus255 | 4:1ec553356dcc | 40 | |
marcus255 | 4:1ec553356dcc | 41 | #endif |