===== Description =====
This demo shows how to communicate with the DS2482 1-Wire interface chip, using the nz_ds2482.h and nz_ds2482.c driver. It uses blocking (synchronous) DS2482 functions. These functions are simpler to implement than the "non blocking" version, but are more complicated to implement. All blocking function names end with "WATE" (Wait and Error processing). For example, the blocking version of the owReadByte() function is owReadByteWATE().
It also flashes the system LED. To add DS2482 support to a project, the following must be done:
- Add nz_ds2482.c to the project, this is the main DS2482 driver file.
- The following additional files are required by nz_ds2482.c, and must be added to the project: nz_circularBufferPwr2.c, nz_helpers.c, nz_netcruzer.c and nz_serI2C.c
- Add "NZ_I2C1_ENABLE" to projdefs.h file (assuming the DS2482 is on I2C 1).
- In code, create a DS2482_INFO structure for each DS2482, and initialize. For example: DS2482_INFO objDS2482; ds2482_init(&objDS2482, 1, DS2482_ADDRESS_00); //Initialize using I2C 1, and DS2482 AD0 and AD1 = 0
- In projdefs.h, do any DS2482, I2C or other configuration required. This is done by copying the configuration section from the *.h files to projdefs.h. Nothing required, defaults will work!
- All done! Can now use ds2482.h driver functions! For example, to write a byte to the 1-Wire Network: owWriteByteWATE(&objDS2482, 0xCC); //Write Skip ROM = 0xCC
This demo can be used with any SBC66 Netcruzer board with an USB Port (not USB Host). It uses USB Commands and Debug Messages sent and received via the Netcruzer USB Terminal app to communicate with board.
Additionally this demo also implements debugging via the USB port and the Netcruzer USB Terminal App. During the program various debug messages are written, which will be displayed on the "Netcruzer USB Terminal" (running on a PC connected to the target board's USB port). This demo also monitors the USB port for Debug messages send to us.
- If "hi" is received, it replies with "Hello"
Use the "Netcruzer USB Terminal" App to send and receive USB Debug messages. It can be downloaded here: https://netcruzer.com/usbterminal/
===== Required Hardware =====
The project requires a SBC66 Netcruzer board with an USB Port (not USB Host), like the SBC66ZL for example. Additionally a DS2482 1-Wire to I2C Bridge chip has to be connected to the I2C 1 port of the SBC66 board. We recommend using one of our Prototype Boards with an iMod port ( PT66ECI for example), and our im1WP 1-Wire DS2482 Interface Module.
===== Building Project =====
This project is located in the "src/demos/1wire/ow_ds2482_demo1_debug" folder of the Netcruzer Download. To compile for Netcruzer Board, open this project in MPLAB X, and select the "Project Configuration" for desired board. For example "SBC66ZL_R1" for the SBC66ZL Revision 1 board. For details click here
===== Programming Board =====
After compiling (build), the board can be programmed via the USB Bootloader or a PIC Programmer. USB Programming is simplified when using the SBC board together with a Prototype Board.
===== File History =====
2013-10-31, David H. (DH):
#define THIS_IS_MAIN_FILE //Uniquely identifies this as the file with the main application entry function main()
#include "HardwareProfile.h"
#define MY_DEBUG_LEVEL DEBUG_LEVEL_INFO
DS2482_INFO objDS2482;
WORD tmrFlashLed;
void printAll_DS18B20(DS2482_INFO* pObj, BOOL parasitePower);
int main(void) {
debugPutString("\nThis is a test debug message from ow_ds2482_demo1_debug");
DIR_SYSLED = OUTPUT_PIN;
delay_ms(10);
if (ds2482_init(&objDS2482, 1, DS2482_ADDRESS_00) == 0) {
delay_ms(12);
printAll_DS18B20(&objDS2482, TRUE);
}
else {
DEBUG_PUT_STR(DEBUG_LEVEL_INFO,
"\nDS2482 Initialization Error!");
}
while(1)
{
LAT_SYSLED = !LAT_SYSLED;
}
}
}
void printAll_DS18B20(DS2482_INFO* pObj, BOOL parasitePower) {
#define MAX_DEVICES 4
BYTE deviceAdr[MAX_DEVICES][8];
BYTE get[10];
WORD_VAL temp;
BYTE i, idx;
BYTE devices = 0;
double fTemp;
owSearchReset(pObj);
debugPutString("\nSearching for DS18B20 devices");
ds2482_resetStatus(pObj);
while (owSearchWATE(pObj) != 0) {
if (pObj->adr64[0] == 0x28) {
debugPutString("\nDS18B20 Found: ");
for (i=0; i<8; i++) {
deviceAdr[devices][i]=pObj->adr64[i];
debugPutHexByte(pObj->adr64[i]);
}
if (++devices == MAX_DEVICES) {
debugPutString("\nFound maximum supported number of devices");
break;
}
}
else {
debugPutString("\nFound unsupported device");
}
}
for(idx=0; idx < devices; idx++) {
ds2482_resetStatus(pObj);
owResetWATE(pObj);
owSelectWATE(pObj, &deviceAdr[idx][0]);
if (parasitePower==TRUE) {
owWriteBytePowerWATE(pObj, 0x44);
}
else {
owWriteByteWATE(pObj, 0x44);
}
delay_ms(750);
owResetWATE(pObj);
owSelectWATE(pObj, &deviceAdr[idx][0]);
owWriteByteWATE(pObj, 0xBE);
if (ds2482_getStatus(pObj) != 0) {
return;
}
debugPutString("\nScratchPAD DATA = 0x");
for (i = 0; i < 9; i++) {
get[i] = owReadByteWATE(pObj);
debugPutHexByte(get[i]);
debugPutChar(' ');
}
temp.byte.LB = get[0];
temp.byte.HB = get[1];
fTemp = (temp.Val & 0x07f0)>>4;
fTemp += 0.0625 * (temp.byte.LB & 0x0f);
printf(
"\nTempC= %f degrees C", fTemp);
}
}
#if defined(HAS_NZ_DEBUGGING)
void debugService(void) {
debugPutString("\nHello");
}
ds2482_reset(&objDS2482);
}
owResetWATE(&objDS2482);
}
debugPutString("\nReceived unknown debug message");
}
}
}
#endif