//----------------------------------------------------------------------------- // Set all devices on 1-Wire to overdrive speed. Return '1' if at least one // overdrive capable device is detected. // int OWOverdriveSkip(unsigned char *data, int data_len) { // set the speed to 'standard' // reset all devices if (OWTouchReset()) // Reset the 1-Wire bus return 0; // Return if no devices found // overdrive skip command OWWriteByte(0x3C); // set the speed to 'overdrive' // do a 1-Wire reset in 'overdrive' and return presence result return OWTouchReset(); }
int do_onewire(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { unsigned short val; int result; int i; unsigned char ow_id[6]; char str[32]; /* * Clear 1-wire bit (open drain with pull-up) */ val = in_be16((void*)(CONFIG_SYS_FPGA_BASE_ADDR + CONFIG_SYS_FPGA_MODE)); val &= ~CONFIG_SYS_FPGA_MODE_1WIRE; /* clear 1-wire bit */ out_be16((void*)(CONFIG_SYS_FPGA_BASE_ADDR + CONFIG_SYS_FPGA_MODE), val); result = OWTouchReset(); if (result != 0) puts("No 1-wire device detected!\n"); OWWriteByte(0x33); /* send read rom command */ OWReadByte(); /* skip family code ( == 0x01) */ for (i = 0; i < 6; i++) ow_id[i] = OWReadByte(); OWReadByte(); /* read crc */ sprintf(str, "%02X%02X%02X%02X%02X%02X", ow_id[0], ow_id[1], ow_id[2], ow_id[3], ow_id[4], ow_id[5]); printf("Setting environment variable 'ow_id' to %s\n", str); setenv("ow_id", str); return 0; }
//----------------------------------------------------------------------------- // Read and return the page data and SHA-1 message authentication code (MAC) // from a DS2432. // int ReadPageMAC(int page, unsigned char *page_data, unsigned char *mac) { int i; unsigned short data_crc16, mac_crc16; // set the speed to 'standard' // select the device if (OWTouchReset()) // Reset the 1-Wire bus return 0; // Return if no devices found OWWriteByte(0xCC); // Send Skip ROM command to select single device // read the page OWWriteByte(0xA5); // Read Authentication command OWWriteByte((page << 5) & 0xFF); // TA1 OWWriteByte(0); // TA2 (always zero for DS2432) // read the page data for (i = 0; i < 32; i++) page_data[i] = OWReadByte(); OWWriteByte(0xFF); // read the CRC16 of command, address, and data data_crc16 = OWReadByte(); data_crc16 |= (OWReadByte() << 8); // delay 2ms for the device MAC computation // read the MAC for (i = 0; i < 20; i++) mac[i] = OWReadByte(); // read CRC16 of the MAC mac_crc16 = OWReadByte(); mac_crc16 |= (OWReadByte() << 8); // check CRC16... return 1; }
int main(void) { unsigned int c; int num=0; /* * Initialize UART library, pass baudrate and AVR cpu clock * with the macro * UART_BAUD_SELECT() (normal speed mode ) * or * UART_BAUD_SELECT_DOUBLE_SPEED() ( double speed mode) */ //uart_init( UART_BAUD_SELECT(UART_BAUD_RATE,F_CPU) ); /* * now enable interrupt, since UART library is interrupt controlled */ //sei(); /* * Transmit string to UART * The string is buffered by the uart library in a circular buffer * and one character at a time is transmitted to the UART using interrupts. * uart_puts() blocks if it can not write the whole string to the circular * buffer */ //uart_puts("String stored in SRAM\n"); /* * Transmit string from program memory to UART */ //uart_puts_P("String stored in FLASH\n"); /* * Transmit single character to UART */ //uart_putc('\r'); /* initialize display, cursor off */ lcd_init(LCD_DISP_ON); /* clear display and home cursor */ lcd_clrscr(); LED_INIT; LED_OFF; unsigned char Buffer_RX[32]; int i; for(;;) { /* * Get received character from ringbuffer * uart_getc() returns in the lower byte the received character and * in the higher byte (bitmask) the last receive error * UART_NO_DATA is returned when no data is available. * */ //uart_puts_P("Kiss my ass\n"); //c = uart_getc(); c=0; //uart_puts("TAREK TAHA ===>>> Wireless is Up and Running\n"); lcd_clrscr(); lcd_gotoxy(16-(num++)%16,0); lcd_puts("<<LCD TEST 1>>\n"); if (OWTouchReset() == 1) { lcd_puts("No Pulse found\n"); } else { lcd_puts("Pulse found\n"); OWWriteByte(OW_READ_ROM_CMD); for (i=0;i<=8;i++) { Buffer_RX[i] = OWReadByte(); lcd_putc(Buffer_RX[i]); } } DelayMs(100); continue; if ( c & UART_NO_DATA ) { /* * no data available from UART */ } else { /* * new data available from UART * check for Frame or Overrun error */ if ( c & UART_FRAME_ERROR ) { /* Framing Error detected, i.e no stop bit detected */ uart_puts_P("UART Frame Error: "); } if ( c & UART_OVERRUN_ERROR ) { /* * Overrun, a character already present in the UART UDR register was * not read by the interrupt handler before the next character arrived, * one or more received characters have been dropped */ uart_puts_P("UART Overrun Error: "); } if ( c & UART_BUFFER_OVERFLOW ) { /* * We are not reading the receive buffer fast enough, * one or more received character have been dropped */ uart_puts_P("Buffer overflow error: "); } /* * send received character back */ if(c=='0') { LED_OFF; uart_puts_P("--->>>Light OFF\n"); } else if(c=='1') { LED_ON; uart_puts_P("--->>>Light ON\n"); } uart_puts_P("Press 0 or 1 to toggle Light\n"); //uart_putc( (unsigned char)c ); } //delay_ms(100); uart_puts("TAREK TAHA"); } }
/** * @brief Reads temperature on a ds1820 temperature sensor * @param temperature Pointer to the measured temperature * @return 0 if temperature read successfully */ int bbb_one_wire_DS1820_read(float* temperature, string* data) { /* int get[10]; char temp_lsb,temp_msb; int k; char temp_f,temp_c; OWTouchReset(); OWWriteByte(0xCC); //Skip ROM OWWriteByte(0x44); // Start Conversion tickDelay(5); OWTouchReset(); OWWriteByte(0xCC); // Skip ROM OWWriteByte(0xBE); // Read Scratch Pad for (k=0;k<9;k++) { get[k] = OWReadByte(); } cout << "ScratchPAD DATA = " << get[8] << get[7] << get[6] << get[5] << get[4] << get[3] << get[2] << get[1] << get[0] << endl; temp_msb = get[1]; // Sign byte + lsbit temp_lsb = get[0]; // Temp data plus lsb if (temp_msb <= 0x80) { temp_lsb = (temp_lsb/2); } // shift to get whole degree temp_msb = temp_msb & 0x80; // mask all but the sign bit if (temp_msb >= 0x80) { temp_lsb = (~temp_lsb)+1; } // twos complement if (temp_msb >= 0x80) { temp_lsb = (temp_lsb/2); }// shift to get whole degree if (temp_msb >= 0x80) { temp_lsb = ((-1)*temp_lsb); } // add sign bit //cout << "TempC= " << (int)temp_lsb << " degrees C" << endl;// print temp. C *temperature = (int)temp_lsb; return 1; */ int i = 0; int a = 1; unsigned short dataCRC16; OWTouchReset(); OWWriteByte(SKIP_ROM); OWWriteByte(CONVERT_T); while(a) { tickDelay(5); if(OWReadBit()) a = 0; } OWTouchReset(); OWWriteByte(SKIP_ROM); OWWriteByte(READ_SCRATCHPAD); *temperature = OWReadByte() + (OWReadByte() << 8); return 1; /* if(OWTouchReset()) return 0; OWWriteByte(0xCC); OWWriteByte(0xA5); OWWriteByte((page << 5) & 0xFF); OWWriteByte(0); for(i = 0; i < 32; i++) *data += OWReadByte() + "-"; OWWriteByte(0xFF); */ // return result; }