void manual_control(void){ uint8_t len = TWI_read(s); if(len){ switch(s[0]){ case CMD_MANUAL: switch(s[2]){ case LEFT: manual_left(); break; case RIGHT: manual_right(); break; case FORWARD: manual_forward(); break; case REVERSE: manual_reverse(); break; case ROTATE_LEFT: rotate_left(); break; case ROTATE_RIGHT: rotate_right(); break; case STOP: manual_stop(); break; } break; } } }
// funkcja do odczytu z EXPANDERA PCF8574 ********************* uint8_t PCF8574_read( uint8_t SLA ) { uint8_t res=0; TWI_start(); TWI_write(SLA + 1); res = TWI_read( NACK ); TWI_stop(); return res; }
int main(void) { TWI_init(); UART_init(); sei(); while(1) { TWI_read(0x50,dat,128); // Czytaj 24c02 EEPROM (A0=A1=A2 = 0) DEBUG_hextable(dat,128); TWI_write(0x50,dat,128); // Zapisz do PCF8583 (A0 = 1) TWI_read(0x51,dat,128); // Czytaj z PCF8583 (A0 = 1) DEBUG_hextable(dat,128); delayms(500); } }
void TWI_read_buf(uint8_t SLA, uint8_t adr, uint8_t len, uint8_t *buf) { TWI_start(); TWI_write(SLA); TWI_write(adr); TWI_start(); TWI_write(SLA + 1); while (len--) *buf++ = TWI_read( len ? ACK : NACK ); TWI_stop(); }
void sfp_read_vendor_name(uint8_t *buf) { uint8_t len=15; TWI_start(); TWI_write(0xa0); TWI_write(0x14); TWI_start(); TWI_write(0xa1); while (len--) *buf++ = TWI_read( len ? ACK : NACK ); TWI_stop(); }
void sfp_read_to_buf(uint8_t SLA, uint8_t len, uint8_t *buf) { TWI_start(); TWI_write(SLA); TWI_write(0xa0); TWI_start(); TWI_write(SLA + 1); while (len--) *buf++ = TWI_read( len ? ACK : NACK ); TWI_stop(); }
uint8_t TWI_read_int(uint8_t SLA) { uint8_t data; TWI_start(); TWI_write(SLA); TWI_start(); TWI_write(SLA + 1); data = TWI_read(NACK); TWI_stop(); return data; }
void EI2C_read_buf(uint8_t device, uint16_t subAddr, uint16_t len, uint8_t *buf) { while (len--) { TWI_start(); TWI_write(device | ((subAddr>>8)<<1) ); TWI_write(subAddr); TWI_start(); TWI_write(device + 1); *buf++ = TWI_read( NACK ); TWI_stop(); subAddr++; } }
int main(void) { unsigned char temp[2]; unsigned int j; DDRB = 0x3F; TWI_first_init(); sei(); TWI_write(DS1631,"\xAC\x0C",2); // Continues conversion mode, 12 bit precision TWI_write(DS1631,"\x51",1); // Start conversion TWI_write(DS1631,"\xAA",1); // Start reading temperature for(;;) { for(j=0; j<50000; j++) wait();// Wait a while, the GCC optimizer trashes empty loops so a volatile nop is inserted TWI_read(DS1631,temp,2); // Read the temperature PORTB = ~temp[0]; } }