void rtc_get_time (void) { twi_send_start(); twi_write_byte(RTC_ADDR & 0xFE); twi_write_byte(RTC_SEC_OFFSET); twi_send_start(); twi_write_byte(RTC_ADDR); twi_read_byte(TRUE); seconds=((twi_byte&0x7f)>>4)*10 + (twi_byte&0xf); twi_read_byte(TRUE); minutes=((twi_byte&0x7f)>>4)*10 + (twi_byte&0xf); twi_read_byte(FALSE); hours=((twi_byte&0x3f)>>4)*10 + (twi_byte&0xf); twi_send_stop(); }
/** Zwraca wskaźnik * @return wartość wskaźnika */ uint16_t log_read_pointer(void) { uint16_t logp; twi_send_start(); twi_write_byte(EXT_EEPROM_ADDR & 0xFE); twi_write_byte(FIRST_WORD(LOG_CONTROL_RECORD_NUMBER) + LOG_CONTROL_POINTER_LSB); twi_write_byte(SECOND_WORD(LOG_CONTROL_RECORD_NUMBER)); twi_send_start(); twi_write_byte(EXT_EEPROM_ADDR); twi_read_byte(TRUE); logp = twi_byte; twi_read_byte(FALSE); logp |= ((uint16_t)twi_byte) << 8; return logp; }
void rtc_get_date (void) { twi_send_start(); twi_write_byte(RTC_ADDR & 0xFE); twi_write_byte(RTC_DAY_OFFSET); twi_send_start(); twi_write_byte(RTC_ADDR); twi_read_byte(TRUE); day=((twi_byte&0x3f)>>4)*10 + (twi_byte&0xf); twi_read_byte(TRUE); wday=twi_byte&0x07; twi_read_byte(TRUE); month=((twi_byte&0x1f)>>4)*10 + (twi_byte&0xf); twi_read_byte(FALSE); year=((twi_byte)>>4)*10 + (twi_byte&0xf); twi_send_stop(); }
uint8_t get_io (uint8_t addr) { twi_send_start(); twi_write_byte(addr); twi_read_byte(FALSE); twi_send_stop(); return twi_byte; }
/** * \brief Reads the series of bytes from the TWI bus * \param package - Package information and data * (see \ref twi_package_t) */ status_code_t twi_master_read(volatile void *twi,const twi_package_t *package) { /* Do a sanity check on the arguments. */ if ((package == NULL) || master_transfer.pkg->length == 0) { return ERR_INVALID_ARG; } if (true == twi_master_busy) { return OPERATION_IN_PROGRESS; } /* Initiate a transaction when the bus is ready. */ /* twi = NULL; megaRF has only one twi */ master_transfer.pkg = (twi_package_t *)package; master_transfer.addr_count = 0; master_transfer.data_count = 0; twi_master_busy = true; if (TWI_SLAVE_NO_INTERNAL_ADDRESS == master_transfer.pkg->addr_length) { master_transfer.state = TWI_READ_DATA; } else { master_transfer.state = TWI_WRITE_IADDR_READ_DATA; } twi_send_start(); /* Wait for the transaction to complete */ while(twi_master_busy); return twi_master_get_status(); }
void rtc_set_time (uint8_t h, uint8_t m, uint8_t s) { twi_send_start(); twi_write_byte(RTC_ADDR & 0xFE); twi_write_byte(RTC_SEC_OFFSET); twi_write_byte(((s/10) << 4) | (s%10)); twi_write_byte(((m/10) << 4) | (m%10)); twi_write_byte(((h/10) << 4) | (h%10)); twi_send_stop(); }
/** Czyta wpis z loga * @param logp wartość wskaźnika * @param *pbuff wskaźnik do bufora, gdzie zostanie zapisany wpis */ void log_read_record_at_pointer(uint16_t logp,uint8_t *pbuff) { uint8_t i; twi_send_start(); twi_write_byte(EXT_EEPROM_ADDR & 0xFE); twi_write_byte(FIRST_WORD(logp)); twi_write_byte(SECOND_WORD(logp)); twi_send_start(); twi_write_byte(EXT_EEPROM_ADDR); for(i=0;i<LOG_BYTES_PER_RECORD-1;i++) { // 7 bajtów z potwierdzeniem twi_read_byte(TRUE); *pbuff++ = twi_byte; } twi_read_byte(FALSE); // 1 bajt bez potwierdzenia *pbuff = twi_byte; twi_send_stop(); }
/** Czyści rekord w logu * @param logp wartość wskaźnika */ void log_clear_record (uint16_t logp) { twi_send_start(); twi_write_byte(EXT_EEPROM_ADDR & 0xFE); twi_write_byte(FIRST_WORD(logp)); twi_write_byte(SECOND_WORD(logp)); twi_write_byte(UINT8_T_DISABLED); twi_send_stop(); _delay_ms(LOG_WRITE_DELAY); }
void rtc_set_date (uint8_t y, uint8_t m, uint8_t d,uint8_t wd) { twi_send_start(); twi_write_byte(RTC_ADDR & 0xFE); twi_write_byte(RTC_DAY_OFFSET); twi_write_byte(((d/10) << 4) | (d%10)); twi_write_byte(wd); twi_write_byte(((m/10) << 4) | (m%10)); twi_write_byte(((y/10) << 4) | (y%10)); twi_send_stop(); }
/** Ustawia wskaźnik wpisu * @param pointer wartość wskaźnika */ void log_write_pointer(uint16_t pointer) { twi_send_start(); twi_write_byte(EXT_EEPROM_ADDR & 0xFE); twi_write_byte(FIRST_WORD(LOG_CONTROL_RECORD_NUMBER) + LOG_CONTROL_POINTER_LSB); twi_write_byte(SECOND_WORD(LOG_CONTROL_RECORD_NUMBER)); twi_write_byte((uint8_t)pointer); twi_write_byte((uint8_t)(pointer >> 8)); twi_send_stop(); _delay_ms(LOG_WRITE_DELAY); }
static void twi_master_write_done(void) { if (TWI_WRITE_DATA == master_transfer.state) { twi_master_data_write(); } else if ((TWI_WRITE_IADDR_WRITE_DATA == master_transfer.state) || (TWI_WRITE_IADDR_READ_DATA == master_transfer.state)) { twi_master_internal_addr_write(); } else if (TWI_READ_DATA == master_transfer.state) { twi_send_start(); } else { /* abnormal */ twi_master_bus_reset(); master_transfer.status = ERR_PROTOCOL; } }
/** Wpisuje kolejne zdarzenie do logu we wskazanym przez wskaźnik miejscu. * @param logp wskaźnik rekordu * @param type typ wpisu * @param val1 warotść 1 * @param val2 warotść 2 * @param val3 warotść 3 */ void log_write_record_at_pointer(uint16_t logp,uint8_t type,uint8_t val1,uint8_t val2, uint8_t val3) { twi_send_start(); twi_write_byte(EXT_EEPROM_ADDR & 0xFE); twi_write_byte(FIRST_WORD(logp)); twi_write_byte(SECOND_WORD(logp)); twi_write_byte(year); twi_write_byte( month << 4 | (type & 0x0F) ); twi_write_byte(day); twi_write_byte(hours); twi_write_byte(minutes); twi_write_byte(val1); twi_write_byte(val2); twi_write_byte(val3); twi_send_stop(); _delay_ms(LOG_WRITE_DELAY); }
void set_io (uint8_t addr,uint8_t byte) { twi_send_start(); twi_write_byte(addr); twi_write_byte(byte); twi_send_stop(); }