first version of m06e01
This commit is contained in:
68
module06/ex01/main.c
Normal file
68
module06/ex01/main.c
Normal file
@@ -0,0 +1,68 @@
|
||||
#include "header.h"
|
||||
|
||||
// sqtatus codes :
|
||||
// -- Master --
|
||||
// TW_BUS_ERROR 0x00 = 0b0 = 0 -> illegal start or stop condition
|
||||
// TW_START 0x08 = 0b1000 = 8 -> start condition transmitted
|
||||
// TW_REP_START 0x10 = 0b10000 = 16 -> repeated start condition transmitted
|
||||
// -- Master Transmitter --
|
||||
// TW_MT_SLA_ACK 0x18 = 0b11000 = 24 -> SLA+W transmitted, ACK received
|
||||
// TW_MT_SLA_NACK 0x20 = 0b100000 = 32 -> SLA+W transmitted, NACK received
|
||||
// TW_MT_DATA_ACK 0x28 = 0b101000 = 40 -> data transmitted, ACK received
|
||||
// TW_MT_DATA_NACK 0x30 = 0b110000 = 48 -> data transmitted, NACK received
|
||||
// TW_MT_ARB_LOST 0x38 = 0b111000 = 56 -> arbitration lost in SLA+W or data
|
||||
// -- Master Receiver --
|
||||
// TW_MR_ARB_LOST 0x38 = 0b111000 = 56 -> arbitration lost in SLA+R or NACK
|
||||
// TW_MR_SLA_ACK 0x40 = 0b1000000 = 64 -> SLA+R transmitted, ACK received
|
||||
// TW_MR_SLA_NACK 0x48 = 0b1001000 = 72 -> SLA+R transmitted, NACK received
|
||||
// TW_MR_DATA_ACK 0x50 = 0b1010000 = 80 -> data received, ACK returned
|
||||
// TW_MR_DATA_NACK 0x58 = 0b1011000 = 88 -> data received, NACK returned
|
||||
// TW_ST_SLA_ACK 0xA8 = 0b10101000 = 168 -> SLA+R received, ACK returned
|
||||
// TW_NO_INFO 0xF8 = 0b11111000 = 248 -> no state information available
|
||||
|
||||
#define SLAVE_ADDRESS 0x38 // doc AHT20, 7.3 : address of thermistor
|
||||
|
||||
void print_hex_value(char c) {}
|
||||
|
||||
void print_status(char *str) {
|
||||
uint8_t status;
|
||||
status = TWSR & 0b11111000; // Table 22-2. Status codes for Master Transmitter Mode
|
||||
uart_printstr(str);
|
||||
uart_printstr(" : ");
|
||||
uart_printstr_itoa_base_endl(status, 2);
|
||||
}
|
||||
|
||||
// description
|
||||
int main() {
|
||||
uart_init();
|
||||
|
||||
print_status("before init");
|
||||
i2c_init();
|
||||
print_status("after init");
|
||||
|
||||
i2c_start();
|
||||
print_status("after start");
|
||||
|
||||
i2c_send_addr_w(SLAVE_ADDRESS);
|
||||
print_status("after SLA+W");
|
||||
|
||||
i2c_write('t');
|
||||
print_status("after write t");
|
||||
|
||||
i2c_write('e');
|
||||
print_status("after write e");
|
||||
|
||||
i2c_write('e');
|
||||
print_status("after write e");
|
||||
|
||||
i2c_write('a');
|
||||
print_status("after write a");
|
||||
|
||||
i2c_write('t');
|
||||
print_status("after write t");
|
||||
|
||||
i2c_stop();
|
||||
print_status("after stop");
|
||||
|
||||
while(1);
|
||||
}
|
||||
Reference in New Issue
Block a user