void OWI_MatchRom(myOneWire* ow) { uint8_t index; OWI_SendByte(ow, OWI_MATCH_ROM); for(index = 0; index < 8; index++) OWI_SendByte(ow, ow->address[index]); return; }
/*! \brief Sends the MATCH ROM command and the ROM id to match against. * * \param romValue A pointer to the ID to match against. * * \param pins A bitmask of the buses to perform the MATCH ROM command on. */ void OWI_MatchRom( unsigned char * romValue, unsigned char pins ) { unsigned char bytesLeft = 8; // Send the MATCH ROM command. OWI_SendByte(OWI_ROM_MATCH, pins); // Do once for each byte. while ( bytesLeft > 0 ) { // Transmit 1 byte of the ID to match. OWI_SendByte(*romValue++, pins); bytesLeft--; } }
/***************************************************************************** * Function name : DS18B20_SetDeviceAccuracy * Parameters : bus - вывод микроконтроллера, который выполн¤ет роль 1WIRE шины * *id - им¤ массива из 8-ми элементов, в котором хранитс¤ * адрес датчика DS18B20 * accuracy - значение точность необходимой дл¤ установлени¤ * 0 - 9bit * 1 - 10bit * 2 - 11bit * 3 - 12bit * * Purpose : јдресует датчик DS18B20, записывает в пам¤ть (scratchpad), * копирует scratchpad в EEPROM. * —ледует вызывать только один раз дл¤ настройки устройства *****************************************************************************/ void DS18B20_SetDeviceAccuracy(unsigned char bus, unsigned char* id, unsigned char accuracy){ OWI_DetectPresence(bus); OWI_MatchRom(id, bus); OWI_SendByte(DS18B20_WRITE_SCRATCHPAD, bus); OWI_SendByte(0x00, bus); //Th OWI_SendByte(0x00, bus); //Tl OWI_SendByte(0x1F | ((accuracy & 0x03)<<5), bus); //Config OWI_DetectPresence(bus); OWI_MatchRom(id, bus); OWI_SendByte(DS18B20_COPY_SCRATCHPAD, bus); while (!OWI_ReadBit(bus)); }
*/ uint16_t ReadDualSwitches( unsigned char bus_pattern, unsigned char * id ) { uint16_t value = 0x0; // continue if bus isn't active if ( 0 == ( ( owiBusMask & bus_pattern ) & 0xFF ) ) { return owiReadStatus_owi_bus_mismatch << 8; } // continue if bus doesn't contain any Dual Switches if ( 0 == ( ( owiDualSwitchMask & bus_pattern ) & 0xFF ) ) { return owiReadStatus_owi_bus_mismatch << 8; } /* Reset, presence.*/ if ( OWI_DetectPresence(bus_pattern) == 0 ) { return owiReadStatus_no_device_presence << 8; } OWI_MatchRom(id, bus_pattern); /* Match id found earlier*/ OWI_SendByte(DS2413_PIO_ACCESS_READ, bus_pattern); //PIO Access read command /*Read first byte and place them in the 16 bit channel variable*/ value = OWI_ReceiveByte(bus_pattern); value &= 0xFF; OWI_DetectPresence(bus_pattern); /* generate RESET to stop slave sending its status and presence pulse*/ return value | owiReadWriteStatus_OK << 8;
/***************************************************************************** * Function name : DS18B20_ReadDevice * Returns : коды - READ_CRC_ERROR, если считанные данные не прошли проверку * READ_SUCCESSFUL, если данные прошли проверку * Parameters : bus - вывод микроконтроллера, который выполн¤ет роль 1WIRE шины * *id - им¤ массива из 8-ми элементов, в котором хранитс¤ * адрес датчика DS18B20 * *temperature - указатель на шестнадцати разр¤дную переменную * в которой будет сохранено считанного зн. температуры * Purpose : ћетод только считывает значение ”∆≈ »«ћ≈–≈ЌЌќ… температуры из scratchpad, * Ќ≈ ¬џѕќЋЌя≈“ »«ћ≈–≈Ќ»≈ * јдресует датчик DS18B20, считывает его пам¤ть - scratchpad, провер¤ет CRC, * сохран¤ет значение температуры в переменной, возвращает код ошибки *****************************************************************************/ unsigned char DS18B20_ReadDevice(unsigned char bus, unsigned char* id, signed int* temperature){ unsigned char scratchpad[9]; OWI_DetectPresence(bus); OWI_MatchRom(id, bus); OWI_SendByte(DS18B20_READ_SCRATCHPAD, bus); for (unsigned char i = 0; i <= 8; i++){ scratchpad[i] = OWI_ReceiveByte(bus); } if(OWI_CheckScratchPadCRC(scratchpad) != OWI_CRC_OK){ return READ_CRC_ERROR; } *temperature = (unsigned int)scratchpad[0]; *temperature |= ((unsigned int)scratchpad[1] << 8); if ((*temperature & 0x8000) != 0){ *temperature = -(~(*temperature) + 1); } //*temperature *= 0.625f; *temperature *= 5; //0.625 = 5/8 *temperature /= 8; return READ_SUCCESSFUL; }
/***************************************************************************** * Function name : DS18B20_StartAllDevicesConverting * Parameters : bus - вывод микроконтроллера, который выполн¤ет роль 1WIRE шины * Purpose : «апускает измерение на всех устройствах одновременно, * ждет окончани¤ преобразовани¤ *****************************************************************************/ void DS18B20_StartAllDevicesConverting(unsigned char bus){ OWI_DetectPresence(bus); OWI_SkipRom(bus); OWI_SendByte(DS18B20_CONVERT_T, bus); /*ждем, когда датчик завершит преобразование*/ //while (!OWI_ReadBit(bus)); _delay_ms(750); }
void OWI_ReadRom(myOneWire* ow) { uint8_t index; OWI_SendByte(ow, 0x33); for(index = 0; index < 8; index++) ow->address[index] = OWI_ReceiveByte(ow); return; }
/***************************************************************************** * Function name : DS18B20_StartDeviceConvertingAndRead * Returns : коды - READ_CRC_ERROR, если считанные данные не прошли проверку * READ_SUCCESSFUL, если данные прошли проверку * Parameters : bus - вывод микроконтроллера, который выполн¤ет роль 1WIRE шины * *id - им¤ массива из 8-ми элементов, в котором хранитс¤ * адрес датчика DS18B20 * *temperature - указатель на шестнадцати разр¤дную переменную * в которой будет сохранено считанного зн. температуры * Purpose : ¬џѕќЋЌя≈“ »«ћ≈–≈Ќ»≈ » ¬ќ«¬–јўј≈“ «Ќј„≈Ќ»≈ “≈ћѕ≈–ј“”–џ * јдресует датчик DS18B20, дает команду на преобразование температуры * ждет, считывает его пам¤ть - scratchpad, провер¤ет CRC, * сохран¤ет значение температуры в переменной, возвращает код ошибки *****************************************************************************/ unsigned char DS18B20_StartDeviceConvertingAndRead(unsigned char bus, unsigned char* id, signed int* temperature){ OWI_DetectPresence(bus); OWI_MatchRom(id, bus); OWI_SendByte(DS18B20_CONVERT_T, bus); /*ждем, когда датчик завершит преобразование*/ //while (!OWI_ReadBit(bus)); _delay_ms(750); return DS18B20_ReadDevice(bus, id, temperature); }
/***************************************************************************** * Function name : DS18B20_ReadTemperature * Returns : коды - READ_CRC_ERROR, если считанные данные не прошли проверку * READ_SUCCESSFUL, если данные прошли проверку * Parameters : bus - вывод микроконтроллера, который выполняет роль 1WIRE шины * *id - имя массива из 8-ми элементов, в котором хранится * адрес датчика DS18B20 * *ds18b20_temperature - указатель на шестнадцати разрядную переменную * в которой будет сохранено считанного зн. температуры * Purpose : Адресует датчик DS18B20, дает команду на преобразование температуры * ждет, считывает его память - scratchpad, проверяет CRC, * сохраняет значение температуры в переменной, возвращает код ошибки *****************************************************************************/ BYTE DS18B20_ReadTemperature(BYTE bus, BYTE * id, WORD* ds18b20_temperature) { unsigned char scratchpad[9]; unsigned char i; /*подаем сигнал сброса команду для адресации устройства на шине подаем команду - запук преобразования */ OWI_DetectPresence(bus); OWI_MatchRom(id, bus); OWI_SendByte(DS18B20_CONVERT_T ,bus); /*ждем, когда датчик завершит преобразование*/ while (!OWI_ReadBit(bus)); /*подаем сигнал сброса команду для адресации устройства на шине команду - чтение внутренней памяти затем считываем внутреннюю память датчика в массив */ OWI_DetectPresence(bus); OWI_MatchRom(id, bus); OWI_SendByte(DS18B20_READ_SCRATCHPAD, bus); for (i = 0; i<=8; i++){ scratchpad[i] = OWI_ReceiveByte(bus); } if(OWI_CheckScratchPadCRC(scratchpad) != OWI_CRC_OK){ return READ_CRC_ERROR; } *ds18b20_temperature = MAKEWORD(scratchpad[0], scratchpad[1]); return READ_SUCCESSFUL; }
/*! \brief Sends the READ ROM command and reads back the ROM id. * * \param romValue A pointer where the id will be placed. * * \param pin A bitmask of the bus to read from. */ void OWI_ReadRom( unsigned char * romValue, unsigned char pin ) { unsigned char bytesLeft = 8; // Send the READ ROM command on the bus. OWI_SendByte(OWI_ROM_READ, pin); // Do 8 times. while ( bytesLeft > 0 ) { // Place the received data in memory. *romValue++ = OWI_ReceiveByte(pin); bytesLeft--; } }
uint8_t OWI_SearchRom(myOneWire *ow) { uint8_t bitIndex = 0; uint8_t byteIndex = 0; uint8_t newDeviation = 0; uint8_t bitMask = 0x01; uint8_t bitA; uint8_t bitB; OWI_SendByte(ow, OWI_SEARCH_ROM); while (bitIndex < 64) { bitA = OWI_ReadBit(ow); bitB = OWI_ReadBit(ow); if(bitA && bitB) { newDeviation = -1; return newDeviation; } else if(bitA ^ bitB) { if(bitA) ow->address[byteIndex] |= bitMask; else ow->address[byteIndex] &= ~bitMask; } else { if(bitIndex == ow->lastDeviation) { ow->address[byteIndex] |= bitMask; } else if(bitIndex > ow->lastDeviation) { ow->address[byteIndex] &= ~bitMask; newDeviation = bitIndex; } else if(!(ow->address[byteIndex] & bitMask)) { newDeviation = bitIndex; } } OWI_WriteBit(ow, ow->address[byteIndex] & bitMask); bitIndex++; bitMask <<= 1; if(!bitMask) { bitMask = 0x01; byteIndex++; } } return newDeviation; }
/* *this function writes the state of dual switch */ uint16_t WriteDualSwitches( unsigned char bus_pattern, unsigned char * id, uint8_t value ) { static unsigned char timeout_flag; static uint32_t count; static uint8_t status; static uint32_t maxcount = OWI_DUAL_SWITCHES_MAXIMUM_WRITE_ACCESS_COUNTS; // continue if bus isn't active if ( 0 == ( ( owiBusMask & bus_pattern ) & 0xFF ) ) { return owiReadStatus_owi_bus_mismatch << 8; } // continue if bus doesn't contain any Dual Switches if ( 0 == ( ( owiDualSwitchMask & bus_pattern ) & 0xFF ) ) { return owiReadStatus_owi_bus_mismatch << 8; } /* Reset, presence.*/ if ( OWI_DetectPresence(bus_pattern) == 0 ) { return owiReadStatus_no_device_presence << 8; } count = maxcount; timeout_flag = FALSE; status = 0; /* Match id found earlier*/ OWI_MatchRom(id, bus_pattern); /* PIO Access write command */ OWI_SendByte(DS2413_PIO_ACCESS_WRITE, bus_pattern); /* loop writing value and its complement, and waiting for confirmation */ while (DS2413_WRITE_CONFIRMATION_PATTERN != status ) { status = 0; /* timeout check */ if ( 0 == --count) { timeout_flag = TRUE; break; } OWI_SendByte( (value |= 0xFC ), bus_pattern); // write value 0:on 1:off OWI_SendByte(~(value |= 0xFC ), bus_pattern); // to confirm, write inverted /*Read status */ status = OWI_ReceiveByte(bus_pattern); status &= 0xFF; } if ( FALSE == timeout_flag ) { /*Read first byte*/ value = OWI_ReceiveByte(bus_pattern); value &= 0xFF; OWI_DetectPresence(bus_pattern); /* generate RESET to stop slave sending its status and presence pulse*/ return value | owiReadWriteStatus_OK << 8; } else { OWI_DetectPresence(bus_pattern); /* generate RESET to stop slave sending its status and presence pulse*/ CommunicationError_p(ERRG, dynamicMessage_ErrorIndex, TRUE, PSTR("OWI Dual Switch write value timeout")); return value | owiWriteStatus_Timeout << 8; } return value | owiReadWriteStatus_OK << 8;
unsigned char OWI_SearchAlarm( unsigned char * bitPattern, unsigned char lastDeviation, unsigned char pin ) { unsigned char currentBit = 1; unsigned char newDeviation = 0; unsigned char bitMask = 0x01; unsigned char bitA; unsigned char bitB; // Send SEARCH ROM command on the bus. OWI_SendByte(OWI_ROM_ALARM, pin); // Walk through all 64 bits. while ( currentBit <= 64 ) { // Read bit from bus twice. bitA = OWI_ReadBit(pin); bitB = OWI_ReadBit(pin); if ( bitA && bitB ) { // Both bits 1 (Error). newDeviation = OWI_ROM_SEARCH_FAILED; return newDeviation; } else if ( bitA ^ bitB ) { // Bits A and B are different. All devices have the same bit here. // Set the bit in bitPattern to this value. if ( bitA ) { ( *bitPattern ) |= bitMask; } else { ( *bitPattern ) &= ~bitMask; } } else // Both bits 0 { // If this is where a choice was made the last time, // a '1' bit is selected this time. if ( currentBit == lastDeviation ) { ( *bitPattern ) |= bitMask; } // For the rest of the id, '0' bits are selected when // discrepancies occur. else if ( currentBit > lastDeviation ) { ( *bitPattern ) &= ~bitMask; newDeviation = currentBit; } // If current bit in bit pattern = 0, then this is // out new deviation. else if ( !( *bitPattern & bitMask ) ) { newDeviation = currentBit; } // IF the bit is already 1, do nothing. else { } } // Send the selected bit to the bus. if ( ( *bitPattern ) & bitMask ) { OWI_WriteBit1(pin); } else { OWI_WriteBit0(pin); } // Increment current bit. currentBit++; // Adjust bitMask and bitPattern pointer. bitMask <<= 1; if ( !bitMask ) { bitMask = 0x01; bitPattern++; } } return newDeviation; }
/*! \brief Sends the SKIP ROM command to the 1-Wire bus(es). * * \param pins A bitmask of the buses to send the SKIP ROM command to. */ void OWI_SkipRom( unsigned char pins ) { // Send the SKIP ROM command on the bus. OWI_SendByte(OWI_ROM_SKIP, pins); }
/* *this function gets the ADC-value of all channels of one device */ uint32_t owiReadChannelsOfSingleADCs( unsigned char bus_pattern, unsigned char * id, uint16_t *array_chn, const int8_t size ) { static const uint8_t maxTrials = 3; uint8_t channelIndex = 0; uint16_t CRC; uint8_t flag = FALSE; uint8_t trialsCounter = maxTrials; uint32_t returnValue; uint8_t loopTurn = 0; uint16_t channelArray[DS2450_TRIPLE_CONVERSION_MAX_LOOP_TURN][4]; uint8_t maxLoopTurn; /* 0 trials, give it a chance */ if (0 == trialsCounter) { trialsCounter++;} if (TRUE == owiAdcTripleReadout) { maxLoopTurn = DS2450_TRIPLE_CONVERSION_MAX_LOOP_TURN; } else { maxLoopTurn = 1; } /*checks*/ printDebug_p(debugLevelEventDebug, debugSystemOWIADC, __LINE__, filename, PSTR("begin")); if ( 0 == ((owiBusMask & bus_pattern) & 0xFF) ) { printDebug_p(debugLevelEventDebug, debugSystemOWIADC, __LINE__, filename, PSTR("passive (bus pattern %#x owiBusMask %#x)"), bus_pattern,owiBusMask); return ((uint32_t) owiReadStatus_owi_bus_mismatch) << OWI_ADC_DS2450_MAX_RESOLUTION; } if ( 0 != ((owiAdcTimeoutAndFailureBusMask & bus_pattern) & 0xFF) ) { //conversion went into timeout owiCreateIdString(owi_id_string, id); CommunicationError_p(ERRG, dynamicMessage_ErrorIndex, TRUE, PSTR("OWI ADC Conversion Error id: %s (bus_pattern %#x)"), owi_id_string, bus_pattern); return ((uint32_t) owiReadStatus_conversion_timeout) << OWI_ADC_DS2450_MAX_RESOLUTION; } #warning TODO: consider the case that bus_pattern has more than one bit active, but the conversion failed/succeeded not on all the same way for ( loopTurn = 0; loopTurn < maxLoopTurn; loopTurn++) { /* Reset, presence */ if ( 0 == OWI_DetectPresence(bus_pattern) ) { return ((uint32_t) owiReadStatus_no_device_presence) << OWI_ADC_DS2450_MAX_RESOLUTION; // Error } /* Send READ MEMORY command * * READ MEMORY [AAH] * * The Read Memory command is used to read conversion results, control/status data and alarm settings. * The bus master follows the command byte with a two byte address (TA1=(T7:T0), TA2=(T15:T8)) that * indicates a starting byte location within the memory map. * * With every subsequent read data time slot the bus master receives data from the DS2450 * starting at the supplied address and continuing until the end of * an eight-byte page is reached. At that point the bus master will receive a 16-bit CRC of the command byte, * address bytes and data bytes. This CRC is computed by the DS2450 and read back by the bus master to check * if the command word, starting address and data were received correctly. If the CRC read by the bus master * is incorrect, a Reset Pulse must be issued and the entire sequence must be repeated. * * Note that the initial pass through the Read Memory flow chart will generate a 16-bit CRC value that is the * result of clearing the CRC-generator and then shifting in the command byte followed by the two address * bytes, and finally the data bytes beginning at the first addressed memory location and continuing through * to the last byte of the addressed page. Subsequent passes through the Read Memory flow chart will * generate a 16-bit CRC that is the result of clearing the CRC-generator and then shifting in the new data * bytes starting at the first byte of the next page. * * (http://datasheets.maximintegrated.com/en/ds/DS2450.pdf) * */ while ( FALSE == flag && trialsCounter != 0) { /* Match id found earlier*/ OWI_MatchRom(id, bus_pattern); // Match id found earlier #warning TODO: is the CRC check described above done here? if this sequence is repeated implement a timeout counter OWI_SendByte(DS2450_READ_MEMORY, bus_pattern); /* set starting address for memory read */ OWI_SendWord(DS2450_ADDRESS_MEMORY_MAP_PAGE_0_CONVERSION_READOUT_INPUT_A_LSB, bus_pattern); //Send two bytes address (ie: 0x00 & 0x00,0x08 & 0x00,0x10 & 0x00,0x18 & 0x00) for (channelIndex = 0; channelIndex < 4; channelIndex++) { // Read a word place it in the 16 bit channel variable. channelArray[loopTurn][channelIndex] = OWI_ReceiveWord(bus_pattern); } /* Receive CRC */ CRC = OWI_ReceiveWord(bus_pattern); /* Check CRC */ flag = TRUE; /*Pseudo check*/ #if 0 if ( checkCRC(...)) { flag = TRUE; } else { trialsCounter--; OWI_DetectPresence(bus_pattern); } #endif } OWI_DetectPresence(bus_pattern); if (FALSE == flag) /*error*/ { returnValue = ((uint32_t) 1 ) | (((uint32_t)owiReadWriteStatus_MAXIMUM_INDEX) << OWI_ADC_DS2450_MAX_RESOLUTION); break; } /*re-convert channel*/ // owiADCConvert(bus_pattern, id); owiADCConvert(bus_pattern, 0); } if ( TRUE == flag ) { clearString_p(resultString, BUFFER_SIZE); int32_t a, b, c; uint32_t m=0; char value[7]; for (uint8_t channel = 0; channel < 4; channel++ ) { if ( FALSE == owiAdcTripleReadout ) { m = channelArray[0][channel]; } else /*triple readout, take the average of the two closest values*/ { a = channelArray[0][channel]; b = channelArray[1][channel]; c = channelArray[2][channel]; if ( abs(a-b) <= abs(a-c) ) { if ( abs(a-b) <= abs(b-c) ) { m = (a+b)/2; } else { m = (b+c)/2; } } else { if ( abs(a-c) <= abs(b-c) ) { m = (a+c)/2; } else { m = (b+c)/2; } } } snprintf(value, 7 - 1, " %.4lX", m); strncat(resultString, value, BUFFER_SIZE - 1); } if ( TRUE == owiAdcTripleReadout) { for ( loopTurn = 0; loopTurn < DS2450_TRIPLE_CONVERSION_MAX_LOOP_TURN; loopTurn++) { for (uint8_t channel = 0; channel < 4; channel++ ) { snprintf(value, 7 - 1, " %.4X", channelArray[loopTurn][channel]); strncat(resultString, value, BUFFER_SIZE - 1); } } } printDebug_p(debugLevelEventDebug, debugSystemOWIADC, __LINE__, filename, PSTR("retrieved data and end")); returnValue = ((uint32_t) 0 ) | (((uint32_t)owiReadWriteStatus_OK) << OWI_ADC_DS2450_MAX_RESOLUTION); } return returnValue; }//END of owiReadChannelsOfSingleADCs function
uint8_t owiADCMemoryWriteByte(unsigned char bus_pattern, unsigned char * id, uint16_t address, uint8_t data, uint8_t maxTrials) { uint16_t receive_CRC; uint8_t flag = FALSE; uint8_t verificationData = 0x0; uint8_t trialsCounter = maxTrials; printDebug_p(debugLevelEventDebug, debugSystemOWIADC, __LINE__, filename, PSTR("writing to ADC memory address: %#x \tdata: %#x"),address, data); /* 0 trials, give it a chance */ if (0 == trialsCounter) { trialsCounter++;} while ( FALSE == flag && trialsCounter != 0) { /* select one or all, depending if id is given */ if ( id == NULL) { /* * SKIP ROM [CCH] * * This command can save time in a single drop bus system by allowing the bus master to access the * memory/ convert functions without providing the 64-bit ROM code. If more than one slave is present on * the bus and a read command is issued following the Skip ROM command, data collision will occur on the * bus as multiple slaves transmit simultaneously (open drain pulldowns will produce a wired-AND result). */ OWI_SendByte(OWI_ROM_SKIP, bus_pattern); } else { /* * MATCH ROM [55H] * * The match ROM command, followed by a 64-bit ROM sequence, allows the bus master to address a * specific DS2450 on a multidrop bus. Only the DS2450 that exactly matches the 64-bit ROM sequence * will respond to the following memory/convert function command. All slaves that do not match the 64-bit * ROM sequence will wait for a reset pulse. This command can be used with a single or multiple devices * on the bus. */ OWI_MatchRom(id, bus_pattern); // Match id found earlier } /* * WRITE MEMORY [55H] * * The Write Memory command is used to write to memory pages 1 and 2 in order to set the channel specific * control data and alarm thresholds. The command can also be used to write the single control byte * on page 3 at address 1Ch. The bus master will follow the command byte with a two byte starting address * (TA1=(T7:T0), TA2=(T15:T8)) and a data byte of (D7:D0). A 16-bit CRC of the command byte, address * bytes, and data byte is computed by the DS2450 and read back by the bus master to confirm that the * correct command word, starting address, and data byte were received. Now the DS2450 copies the data * byte to the specified memory location. With the next eight time slots the bus master receives a copy of * the same byte but read from memory for verification. If the verification fails, a Reset Pulse should be * issued and the current byte address should be written again. * If the bus master does not issue a Reset Pulse and the end of memory was not yet reached, the DS2450 * will automatically increment its address counter to address the next memory location. The new two-byte * address will also be loaded into the 16-bit CRC-generator as a starting value. The bus master will send * the next byte using eight write time slots. As the DS2450 receives this byte it also shifts * it into the CRCgenerator and the result is a 16-bit CRC of the new data byte and the new address. * With the next sixteen read time slots the bus master * will read this 16-bit CRC from the DS2450 to verify that the address * incremented properly and the data byte was received correctly. Following the CRC the master receives * the byte just written as read from the memory. If the CRC or read-back byte is incorrect, a Reset Pulse * should be issued in order to repeat the Write Memory command sequence. * Note that the initial pass through the Write Memory flow chart will generate a 16-bit CRC value that is * the result of shifting the command byte into the CRC-generator, followed by the two address bytes, and * finally the data byte. Subsequent passes through the Write Memory flow chart due to the DS2450 * automatically incrementing its address counter will generate a 16-bit CRC that is the result of loading (not * shifting) the new (incremented) address into the CRC-generator and then shifting in the new data byte. * The decision to continue after having received a bad CRC or if the verification fails is made entirely by * the bus master. Write access to the conversion read-out registers is not possible. If a write attempt is * made to a page 0 address the device will follow the Write Memory flow chart correctly but the * verification of the data byte read back from memory will usually fail. The Write Memory command * sequence can be ended at any point by issuing a Reset Pulse. * */ OWI_SendByte(DS2450_WRITE_MEMORY, bus_pattern); OWI_SendWord(address, bus_pattern); OWI_SendByte(data, bus_pattern); /* receive 16bit CRC */ receive_CRC = OWI_ReceiveWord(bus_pattern); /* IMPORTANT AFTER EACH 'MEMORY WRITE' OPERATION to start memory writing*/ /* only possible if there is not OWI_ROM_SKIP, so wait until this device specific is implemented*/ if (id != NULL) { #warning TODO: add a complex check on the CRC, including the correct address, if in single device mode /*verify written data*/ verificationData = OWI_ReceiveByte(bus_pattern); if ( data == verificationData ) /* check passed */ { flag = TRUE; } else { trialsCounter--; } } else { flag = TRUE; } /* ending the Write Memory command sequence by issuing a Reset Pulse*/ OWI_DetectPresence(bus_pattern); /*the "DetectPresence" function includes sending a Reset Pulse*/ } /*end of while loop */ if (FALSE == flag) { return 1; } else { return 0; } }