/* * Mega328P_SPI_MCP4922.c * * Created: 08.01.2019 22:27:33 * Author : Paul */ #define F_CPU 8000000UL #define LM75 0x4F // device address of EEPROM 24C02, see datasheet #include #include //AVR Register und Konstantendefinitionen #include //AVR Interrupt Vektoren #include #include #include #include #include #include #include #include "uart.h" #include #include #include #include "i2cmaster.h" #define PRINT(string, ...) printf_P(PSTR(string), ##__VA_ARGS__) static int putchar__(char c, FILE *stream) { uart_putc(c); return 0; } static FILE mystdout = FDEV_SETUP_STREAM(putchar__, 0, _FDEV_SETUP_WRITE); int main(void) { uart_init(UART_BAUD_SELECT(9600UL, F_CPU)); stdout = &mystdout; sei() ; PRINT("Start Main\n\n"); i2c_init(); // init I2C interface _delay_ms(300); unsigned char tempHigh; unsigned char tempLow; while (1) { PRINT("Start while\n\n"); i2c_start_wait(LM75+I2C_WRITE); // set device address and write mode PRINT("5\n\n"); i2c_write(0x00); // write address 0 = Temp Register PRINT("6\n\n"); i2c_rep_start(LM75+I2C_READ); // set device address and read mode PRINT("7\n\n"); tempHigh = i2c_readAck(); // read one byte form address 0H tempLow = i2c_readNak(); // read one byte from address 0L PRINT("8\n\n"); i2c_stop(); PRINT("Register: %d\n", tempHigh); PRINT("Register: %d\n", tempLow); PRINT("Alive\n\n"); _delay_ms(1000); } }