57 int DS2485_WriteMemory(DS2485_memory_page_T pgNumber,
const uint8_t *pgData)
62 const int txLength = 35;
63 const int delay_msec = tWM_MSEC;
64 const int rxLength = 2;
66 uint8_t packet[txLength];
67 uint8_t response[rxLength];
70 packet[0] = DFC_WRITE_MEMORY;
71 packet[1] =
sizeof(packet) - 2;
73 memcpy(&packet[3], &pgData[0], 32);
76 if ((error =
DS2485_ExecuteCommand(packet,
sizeof(packet), delay_msec*1000, response,
sizeof(response))) != 0)
81 switch (response[1]) {
87 error = RB_WRITE_PROTECTED;
91 error = RB_INVALID_PARAMETER;
102 int DS2485_ReadMemory(DS2485_memory_page_T pgNumber, uint8_t *pgData)
107 const int txLength = 3;
108 const int delay_msec = tRM_MSEC;
109 const int rxLength = 34;
111 uint8_t packet[txLength];
112 uint8_t response[rxLength];
115 packet[0] = DFC_READ_MEMORY;
116 packet[1] =
sizeof(packet) - 2;
117 packet[2] = pgNumber;
120 if ((error =
DS2485_ExecuteCommand(packet,
sizeof(packet), delay_msec*1000, response,
sizeof(response))) != 0)
126 memcpy(&pgData[0], &response[2],
sizeof(response) - 2);
128 switch (response[1]) {
134 error = RB_INVALID_PARAMETER;
145 int DS2485_ReadStatus(DS2485_status_outputs_T output, uint8_t *status)
150 const int txLength = 3;
151 const int delay_msec = tRM_MSEC;
155 case PAGE_PROTECTIONS:
163 uint8_t packet[txLength];
164 uint8_t response[rxLength];
167 packet[0] = DFC_READ_STATUS;
168 packet[1] =
sizeof(packet) - 2;
172 if ((error =
DS2485_ExecuteCommand(packet,
sizeof(packet), delay_msec*1000, response,
sizeof(response))) != 0)
178 memcpy(&status[0], &response[2],
sizeof(response) - 2);
180 switch (response[1]) {
186 error = RB_INVALID_PARAMETER;
197 int DS2485_SetI2cAddress(uint8_t newAddress)
202 const int txLength = 3;
203 const int delay_msec = tWS_MSEC;
204 const int rxLength = 2;
206 uint8_t packet[txLength];
207 uint8_t response[rxLength];
210 packet[0] = DFC_SET_I2C_ADDRESS;
211 packet[1] =
sizeof(packet) - 2;
212 packet[2] = newAddress << 1;
215 if ((error =
DS2485_ExecuteCommand(packet,
sizeof(packet), delay_msec*1000, response,
sizeof(response))) != 0)
220 switch (response[1]) {
226 error = RB_SET_ADDRESS_FAIL;
237 int DS2485_SetPageProtection(DS2485_memory_page_T pgNumber, DS2485_page_protection_T protection)
242 const int txLength = 4;
243 const int delay_msec = tWS_MSEC;
244 const int rxLength = 2;
246 uint8_t packet[txLength];
247 uint8_t response[rxLength];
250 packet[0] = DFC_SET_PAGE_PROTECTION;
251 packet[1] =
sizeof(packet) - 2;
252 packet[2] = pgNumber;
253 packet[3] = protection;
256 if ((error =
DS2485_ExecuteCommand(packet,
sizeof(packet), delay_msec*1000, response,
sizeof(response))) != 0)
261 switch (response[1]) {
267 error = RB_ALREADY_PROTECTED;
271 error = RB_INVALID_PARAMETER;
282 int DS2485_ReadOneWirePortConfig(DS2485_configuration_register_address_T reg, uint8_t *regData)
287 const int txLength = 3;
288 const int delay_usec = tOP_USEC;
300 uint8_t packet[txLength];
301 uint8_t response[rxLength];
304 packet[0] = DFC_READ_ONE_WIRE_PORT_CONFIG;
305 packet[1] =
sizeof(packet) - 2;
309 if ((error =
DS2485_ExecuteCommand(packet,
sizeof(packet), delay_usec, response,
sizeof(response))) != 0)
315 memcpy(®Data[0], &response[2],
sizeof(response) - 2);
317 switch (response[1]) {
330 int DS2485_WriteOneWirePortConfig(DS2485_configuration_register_address_T reg,
const uint8_t *regData)
335 const int txLength = 5;
336 const int delay_usec = tOP_USEC + 1000;
337 const int rxLength = 2;
339 uint8_t packet[txLength];
340 uint8_t response[rxLength];
343 packet[0] = DFC_WRITE_ONE_WIRE_PORT_CONFIG;
344 packet[1] =
sizeof(packet) - 2;
346 packet[3] = regData[0];
347 packet[4] = regData[1];
351 if ((error =
DS2485_ExecuteCommand(packet,
sizeof(packet), delay_usec, response,
sizeof(response))) != 0)
356 switch (response[1]) {
362 error = RB_INVALID_PARAMETER;
373 int DS2485_MasterReset(
void)
378 const int txLength = 1;
379 const int delay_usec = tOP_USEC;
380 const int rxLength = 2;
382 uint8_t packet[txLength];
383 uint8_t response[rxLength];
386 packet[0] = DFC_MASTER_RESET;
389 if ((error =
DS2485_ExecuteCommand(packet,
sizeof(packet), delay_usec, response,
sizeof(response))) != 0)
394 switch (response[1]) {
400 error = RB_MASTER_RESET_FAIL;
411 int DS2485_OneWireScript(
const uint8_t *script, uint8_t script_length,
double accumulativeOneWireTime, uint8_t commandsCount, uint8_t *scriptResponse, uint8_t scriptResponse_length)
416 const int txLength = script_length + 2;
417 const int delay_usec = tOP_USEC + (tSEQ_USEC*(commandsCount)) + accumulativeOneWireTime + 1000;
418 const int rxLength = scriptResponse_length + 2;
420 uint8_t packet[txLength];
421 uint8_t response[rxLength];
424 packet[0] = DFC_ONE_WIRE_SCRIPT;
425 packet[1] =
sizeof(packet) - 2;
426 memcpy(&packet[2], &script[0], script_length);
429 if ((error =
DS2485_ExecuteCommand(packet,
sizeof(packet), delay_usec, response,
sizeof(response))) != 0)
435 memcpy(&scriptResponse[0], &response[2],
sizeof(response) - 2);
437 switch (response[1]) {
443 error = RB_INVALID_PARAMETER;
447 error = RB_COMMS_FAIL;
458 int DS2485_OneWireBlock(
const uint8_t *blockData,
int blockData_Length, uint8_t *ow_data,
bool ow_reset,
bool ignore,
bool spu,
bool pe)
461 one_wire_speeds master_speed;
464 double one_wire_time;
475 if ((error = OneWire_Get_OneWireMasterSpeed(&master_speed)) != 0)
480 if(master_speed != STANDARD)
482 if ((error = OneWire_Get_tRSTL(&t_rstl, OVERDRIVE)) != 0)
486 if ((error = OneWire_Get_tRSTH(&t_rsth, OVERDRIVE)) != 0)
490 if ((error = OneWire_Get_tW0L(&t_w0l, OVERDRIVE)) != 0)
494 if ((error = OneWire_Get_tREC(&t_rec, OVERDRIVE)) != 0)
501 if ((error = OneWire_Get_tRSTL(&t_rstl, STANDARD)) != 0)
505 if ((error = OneWire_Get_tRSTH(&t_rsth, STANDARD)) != 0)
509 if ((error = OneWire_Get_tW0L(&t_w0l, STANDARD)) != 0)
513 if ((error = OneWire_Get_tREC(&t_rec, STANDARD)) != 0)
520 t_slot = t_w0l + t_rec;
521 ow_rst_time = t_rstl + t_rsth;
522 one_wire_time = ((t_slot * 8) * (blockData_Length));
525 one_wire_time += ow_rst_time;
529 const int txLength = blockData_Length + 3;
530 const int delay_usec = tOP_USEC + (tSEQ_USEC*(blockData_Length + ow_reset)) + one_wire_time;
531 const int rxLength = blockData_Length + 2;
533 uint8_t packet[txLength];
534 uint8_t response[rxLength];
537 packet[0] = DFC_ONE_WIRE_BLOCK;
538 packet[1] =
sizeof(packet) - 2;
539 packet[2] = (pe << 3) | (spu << 2) | (ignore << 1) | (ow_reset << 0);
540 memcpy(&packet[3], &blockData[0], blockData_Length);
543 if ((error =
DS2485_ExecuteCommand(packet,
sizeof(packet), delay_usec, response,
sizeof(response))) != 0)
549 memcpy(&ow_data[0], &response[2],
sizeof(response) - 2);
551 switch (response[1]) {
557 error = RB_INVALID_PARAMETER;
561 error = RB_COMMS_FAIL;
565 error = RB_NOT_DETECTED;
576 int DS2485_OneWireWriteBlock(
const uint8_t *writeData,
int writeData_Length,
bool ow_reset,
bool ignore,
bool spu)
579 one_wire_speeds master_speed;
582 double one_wire_time;
593 if ((error = OneWire_Get_OneWireMasterSpeed(&master_speed)) != 0)
598 if(master_speed != STANDARD)
600 if ((error = OneWire_Get_tRSTL(&t_rstl, OVERDRIVE)) != 0)
604 if ((error = OneWire_Get_tRSTH(&t_rsth, OVERDRIVE)) != 0)
608 if ((error = OneWire_Get_tW0L(&t_w0l, OVERDRIVE)) != 0)
612 if ((error = OneWire_Get_tREC(&t_rec, OVERDRIVE)) != 0)
619 if ((error = OneWire_Get_tRSTL(&t_rstl, STANDARD)) != 0)
623 if ((error = OneWire_Get_tRSTH(&t_rsth, STANDARD)) != 0)
627 if ((error = OneWire_Get_tW0L(&t_w0l, STANDARD)) != 0)
631 if ((error = OneWire_Get_tREC(&t_rec, STANDARD)) != 0)
638 t_slot = t_w0l + t_rec;
639 ow_rst_time = t_rstl + t_rsth;
640 one_wire_time = ((t_slot * 8) * (writeData_Length));
643 one_wire_time += ow_rst_time;
647 const int txLength = writeData_Length + 3;
648 const int delay_usec = tOP_USEC + (tSEQ_USEC*(writeData_Length + ow_reset)) + one_wire_time;
649 const int rxLength = 2;
651 uint8_t packet[txLength];
652 uint8_t response[rxLength];
655 packet[0] = DFC_ONE_WIRE_WRITE_BLOCK;
656 packet[1] =
sizeof(packet) - 2;
657 packet[2] = (spu << 2) | (ignore << 1) | (ow_reset << 0);
658 memcpy(&packet[3], &writeData[0], writeData_Length);
661 if ((error =
DS2485_ExecuteCommand(packet,
sizeof(packet), delay_usec, response,
sizeof(response))) != 0)
666 switch (response[1]) {
672 error = RB_COMMS_FAIL;
676 error = RB_NO_PRESENCE;
680 error = RB_NO_MATCH_WRITES;
684 error = RB_INVALID_PARAMETER;
695 int DS2485_OneWireReadBlock(uint8_t *readData, uint8_t bytes)
698 one_wire_speeds master_speed;
701 double one_wire_time;
711 if ((error = OneWire_Get_OneWireMasterSpeed(&master_speed)) != 0)
716 if(master_speed != STANDARD)
718 if ((error = OneWire_Get_tRSTL(&t_rstl, OVERDRIVE)) != 0)
722 if ((error = OneWire_Get_tRSTH(&t_rsth, OVERDRIVE)) != 0)
726 if ((error = OneWire_Get_tW0L(&t_w0l, OVERDRIVE)) != 0)
730 if ((error = OneWire_Get_tREC(&t_rec, OVERDRIVE)) != 0)
737 if ((error = OneWire_Get_tRSTL(&t_rstl, STANDARD)) != 0)
741 if ((error = OneWire_Get_tRSTH(&t_rsth, STANDARD)) != 0)
745 if ((error = OneWire_Get_tW0L(&t_w0l, STANDARD)) != 0)
749 if ((error = OneWire_Get_tREC(&t_rec, STANDARD)) != 0)
756 t_slot = t_w0l + t_rec;
757 one_wire_time = ((t_slot * 8) * (bytes));
761 const int txLength = 3;
762 const int delay_usec = tOP_USEC + (tSEQ_USEC*(bytes)) + one_wire_time;
763 const int rxLength = bytes + 2;
765 uint8_t packet[txLength];
766 uint8_t response[rxLength];
769 packet[0] = DFC_ONE_WIRE_READ_BLOCK;
770 packet[1] =
sizeof(packet) - 2;
774 if ((error =
DS2485_ExecuteCommand(packet,
sizeof(packet), delay_usec, response,
sizeof(response))) != 0)
780 memcpy(&readData[0], &response[2],
sizeof(response) - 2);
782 switch (response[1]) {
788 error = RB_COMMS_FAIL;
792 error = RB_INVALID_LENGTH;
803 int DS2485_OneWireSearch(uint8_t *romId, uint8_t code,
bool ow_reset,
bool ignore,
bool search_rst,
bool *flag)
806 one_wire_speeds master_speed;
809 double one_wire_time;
820 if ((error = OneWire_Get_OneWireMasterSpeed(&master_speed)) != 0)
825 if(master_speed != STANDARD)
827 if ((error = OneWire_Get_tRSTL(&t_rstl, OVERDRIVE)) != 0)
831 if ((error = OneWire_Get_tRSTH(&t_rsth, OVERDRIVE)) != 0)
835 if ((error = OneWire_Get_tW0L(&t_w0l, OVERDRIVE)) != 0)
839 if ((error = OneWire_Get_tREC(&t_rec, OVERDRIVE)) != 0)
846 if ((error = OneWire_Get_tRSTL(&t_rstl, STANDARD)) != 0)
850 if ((error = OneWire_Get_tRSTH(&t_rsth, STANDARD)) != 0)
854 if ((error = OneWire_Get_tW0L(&t_w0l, STANDARD)) != 0)
858 if ((error = OneWire_Get_tREC(&t_rec, STANDARD)) != 0)
865 t_slot = t_w0l + t_rec;
866 ow_rst_time = t_rstl + t_rsth;
867 one_wire_time = ((t_slot * 8) * (64));
870 one_wire_time += ow_rst_time;
874 const int txLength = 4;
875 const int delay_usec = tOP_USEC + (tSEQ_USEC*(64 + ow_reset)) + one_wire_time;
876 const int rxLength = 11;
878 uint8_t packet[txLength];
879 uint8_t response[rxLength];
894 packet[0] = DFC_ONE_WIRE_SEARCH;
895 packet[1] =
sizeof(packet) - 2;
896 packet[2] = (search_rst << 2) | (ignore << 1) | (ow_reset << 0);
900 if ((error =
DS2485_ExecuteCommand(packet,
sizeof(packet), delay_usec, response,
sizeof(response))) != 0)
906 memcpy(&romId[0], &response[2], 8);
907 *flag = response[10];
909 switch (response[1]) {
915 error = RB_NOT_DETECTED;
919 error = RB_NO_PRESENCE;
923 error = RB_INVALID_PARAMETER;
934 int DS2485_FullCommandSequence(
const uint8_t *owData,
int owData_Length, uint8_t *rom_id, DS2485_full_command_sequence_delays_msecs_T ow_delay_msec, uint8_t *ow_rslt_data, uint8_t ow_rslt_len)
937 one_wire_speeds master_speed;
940 double one_wire_time;
951 if ((error = OneWire_Get_OneWireMasterSpeed(&master_speed)) != 0)
956 if(master_speed != STANDARD)
958 if ((error = OneWire_Get_tRSTL(&t_rstl, OVERDRIVE)) != 0)
962 if ((error = OneWire_Get_tRSTH(&t_rsth, OVERDRIVE)) != 0)
966 if ((error = OneWire_Get_tW0L(&t_w0l, OVERDRIVE)) != 0)
970 if ((error = OneWire_Get_tREC(&t_rec, OVERDRIVE)) != 0)
977 if ((error = OneWire_Get_tRSTL(&t_rstl, STANDARD)) != 0)
981 if ((error = OneWire_Get_tRSTH(&t_rsth, STANDARD)) != 0)
985 if ((error = OneWire_Get_tW0L(&t_w0l, STANDARD)) != 0)
989 if ((error = OneWire_Get_tREC(&t_rec, STANDARD)) != 0)
996 t_slot = t_w0l + t_rec;
997 ow_rst_time = t_rstl + t_rsth;
998 one_wire_time = ow_rst_time + ((t_slot * 8) * (18 + owData_Length + ow_rslt_len));
1001 const int txLength = owData_Length + 11;
1002 const int delay_usec = tOP_USEC + (tSEQ_USEC*(19 + owData_Length + ow_rslt_len)) + one_wire_time + (ow_delay_msec * 2000);
1003 const int rxLength = ow_rslt_len + 3;
1005 uint8_t packet[txLength];
1006 uint8_t response[rxLength];
1009 packet[0] = DFC_FULL_COMMAND_SEQUENCE;
1010 packet[1] =
sizeof(packet) - 2;
1011 packet[2] = ow_delay_msec;
1012 memcpy(&packet[3], &rom_id[0], 8);
1013 memcpy(&packet[11], &owData[0], owData_Length);
1016 if ((error =
DS2485_ExecuteCommand(packet,
sizeof(packet), delay_usec, response,
sizeof(response))) != 0)
1022 memcpy(&ow_rslt_data[0], &response[3],
sizeof(response) - 3);
1024 switch (response[1]) {
1030 error = RB_INCORRECT_CRC;
1041 int DS2485_ComputeCrc16(
const uint8_t *crcData,
int crcData_Length, uint8_t *crc16)
1046 const int txLength = crcData_Length + 2;
1047 const int delay_usec = tOP_USEC;
1048 const int rxLength = 4;
1050 uint8_t packet[txLength];
1051 uint8_t response[rxLength];
1054 packet[0] = DFC_COMPUTE_CRC16;
1055 packet[1] =
sizeof(packet) - 2;
1056 memcpy(&packet[2], &crcData[0], crcData_Length);
1059 if ((error =
DS2485_ExecuteCommand(packet,
sizeof(packet), delay_usec, response,
sizeof(response))) != 0)
1065 memcpy(&crc16[0], &response[2],
sizeof(response) - 2);
1067 switch (response[1]) {
1073 error = RB_INVALID_LENGTH;
1077 error = RB_LENGTH_MISMATCH;
int DS2485_ExecuteCommand(const uint8_t *packet, int packetSize, int delay_uSec, uint8_t *response, int responseSize)
Platform-specific I2C command interface implemented in DS2485_port_xxxx.c Returns 'error' (0 if compl...
General library for the DS2485, supporting the higher-level one_wire.c/.h API.
General 1-Wire API using the DS2485 1-Wire master.