Да фьюзы соответствуют //=================================================== //Error code I2C Bus //=================================================== #define ERROR_START 0x10 #define ERROR_MASTER_ASK 0x11 #define ERROR_MT_DATA_ASK 0x12 #define ERROR_START_REPEAT 0x13 #define ERROR_ASK_READ 0x14 #define ERROR_ASK_DATA_READ 0x15 #define NO_ERROR 0x00 //=================================================== #define HARD_START_CONDITION 0xA4 #define HARD_STOP_CONDITION 0x94 #define HARD_RESTORE_REG 0x84 #define HARD_RESTORE_ASK 0xC4
//================================================================ // Инициализация RTC //================================================================ void hardRTCInit(void) { unsigned char r; r = i2cReadBlock(ADDRES, 0x0E, sizeof(testDS), (unsigned char *)&testDS); r = 0x40; i2cWriteBlock(ADDRES, 0x0E, 1, &r); r = i2cReadBlock(ADDRES, 0x02, sizeof(testDS), (unsigned char *)&testDS); }
//================================================================ //Read block data from I2C Bus //Чтение блока данных по шине I2C //================================================================ unsigned char i2cReadBlock(unsigned char addres, unsigned char subaddres, unsigned char size, unsigned char *data) { static unsigned char _size; _size = size; //Start condition TWCR = HARD_START_CONDITION; while (!(TWCR & 0x80)); if ((TWSR & 0xF8) != _START) { TWCR = HARD_STOP_CONDITION; return ERROR_START; } //Send addres TWDR = addres; TWCR = HARD_RESTORE_REG; while (!(TWCR & 0x80)); if ((TWSR & 0xF8) != _MT_SLA_ACK) { TWCR = HARD_STOP_CONDITION; return ERROR_ASK_READ; } //Send subaddres TWDR = subaddres; TWCR = HARD_RESTORE_REG; while (!(TWCR & 0x80)); if ((TWSR & 0xF8) != _MT_DATA_ACK) { TWCR = HARD_STOP_CONDITION; return ERROR_MT_DATA_ASK; } //Start condition TWCR = HARD_START_CONDITION; while (!(TWCR & 0x80)); if ((TWSR & 0xF8) != _START_REPEAT) { TWCR = HARD_STOP_CONDITION; return ERROR_START; } //Send addres TWDR = addres+1; TWCR = HARD_RESTORE_REG; while (!(TWCR & 0x80)); if ((TWSR & 0xF8) != _MT_SLA_ACK_READ) { TWCR = HARD_STOP_CONDITION; return ERROR_ASK_READ; } //Recive data TWCR = HARD_RESTORE_ASK; while (!(TWCR & 0x80)); if ((TWSR & 0xF8) != _MT_DATA_ACK_READ) { TWCR = HARD_STOP_CONDITION; return ERROR_ASK_DATA_READ; } if(size) { *data = TWDR; ++data; _size--; } else _size = TWDR; while(_size--) { if(!_size) {//Send one byte of block TWCR = HARD_RESTORE_REG; while (!(TWCR & 0x80)); if ((TWSR & 0xF8) != _MT_DATA_NOT_ACK_READ) { TWCR = HARD_STOP_CONDITION; return ERROR_ASK_DATA_READ; } *data = TWDR; ++data; } else { TWCR = HARD_RESTORE_ASK; while (!(TWCR & 0x80)); if ((TWSR & 0xF8) != _MT_DATA_ACK_READ) { TWCR = HARD_STOP_CONDITION; return ERROR_ASK_DATA_READ; } *data = TWDR; ++data; } } TWCR = HARD_STOP_CONDITION; return NO_ERROR; }
|