m06e00 ok
This commit is contained in:
@@ -90,5 +90,5 @@ avrdude done. Thank you.
|
||||
|
||||
## screen
|
||||
|
||||
- (optional) `export XTERM=xterm`
|
||||
- (optional) `export TERM=xterm`
|
||||
- `screen /dev/ttyUSB0 115200`
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#define TWI_PRESCALE_VALUE 1 // can be 1, 4, 16, 64
|
||||
#define TWI_FREQ 100000UL // 100kHz I2C
|
||||
#define SLAVE_ADDRESS 42 // 22.3.3 : address 0000000 and 1111xxx are reserved, 42 is 0101010
|
||||
#define SLAVE_ADDRESS 0x38 // doc AHT20, 7.3 : address of thermistor
|
||||
|
||||
void i2c_init(void) {
|
||||
TWSR = TWI_PRESCALE_SET(TWI_PRESCALE_VALUE); // 22.9.3 : (Status Register) set prescaler
|
||||
@@ -14,7 +14,6 @@ void i2c_start(void) {
|
||||
while (!(TEST(TWCR, TWINT))); // p225 example code : Wait for TWINT Flag set. This indicates that the START condition has been transmitted
|
||||
|
||||
uint8_t status = TWSR & 0b11111000; // Table 22-2. Status codes for Master Transmitter Mode
|
||||
uart_printstr_itoa_base_endl(status, 2);
|
||||
if (status != TW_START && status != TW_REP_START) {
|
||||
TWCR = SEND_STOP_CONDITION;
|
||||
return;
|
||||
|
||||
@@ -1,11 +1,34 @@
|
||||
#include "header.h"
|
||||
|
||||
// status before init : 11111000
|
||||
// status after init : 11111000
|
||||
// status after start : 1000
|
||||
// status after stop : 11111000
|
||||
|
||||
// description
|
||||
int main() {
|
||||
uint8_t status;
|
||||
|
||||
uart_init();
|
||||
|
||||
status = TWSR & 0b11111000; // Table 22-2. Status codes for Master Transmitter Mode
|
||||
uart_printstr("status before init : ");
|
||||
uart_printstr_itoa_base_endl(status, 2);
|
||||
|
||||
i2c_init();
|
||||
status = TWSR & 0b11111000; // Table 22-2. Status codes for Master Transmitter Mode
|
||||
uart_printstr("status after init : ");
|
||||
uart_printstr_itoa_base_endl(status, 2);
|
||||
|
||||
i2c_start();
|
||||
status = TWSR & 0b11111000; // Table 22-2. Status codes for Master Transmitter Mode
|
||||
uart_printstr("status after start : ");
|
||||
uart_printstr_itoa_base_endl(status, 2);
|
||||
|
||||
i2c_stop();
|
||||
status = TWSR & 0b11111000; // Table 22-2. Status codes for Master Transmitter Mode
|
||||
uart_printstr("status after stop : ");
|
||||
uart_printstr_itoa_base_endl(status, 2);
|
||||
|
||||
while(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user