Multiple DS18S20
Multiple DS18S20
Hello, i need help. want to connect 2 or more ds18s20 on one wire. I know my ROM addresses, but i cant make it run. here is my source code:
// LCD ekrano prijungimai
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
char ROMCODE_A [8] = {0x10, 0x30, 0xC5, 0xC8, 0x00, 0x00, 0x00, 0xC3};
char ROMCODE_B [8] = {0xF4, 0x00, 0x00, 0x00,0xC8, 0xC5, 0x31, 0x10};
const unsigned short TEMP_RESOLUTION = 9;// nustatomas konstantos tipas ir sensoriaus tipas
char *text = "000.0"; //nustatomas kintamojo tipas ir pradinė jo reikšmė
unsigned temp; //kintamasis temperatūros nuskaitymui
void Display_Temp(unsigned int temp2write) {
const unsigned short RES_SHIFT = TEMP_RESOLUTION - 8; //priklauso nuo sensoriaus rezoliucijos
char temp_whole;
unsigned int temp_fraction;
int neigtemp = 1;
// Tikrinti ar temperatūra nėra neigiama
if (temp2write & 0x8000) {
text[0] = '-';
temp2write = ~temp2write + 1;
neigtemp=1;
}
else {
neigtemp=0;
}
// gauti kintamąji temp_whole
temp_whole = temp2write >> RES_SHIFT ;
if (!neigtemp) { // tikrinti kintamajį neigtemp
if (temp_whole/100) // Perversti temp_whole į vienetus
text[0] = temp_whole/100 + 48;
else
text[0] = ' ';
}
text[1] = (temp_whole/10)%10+48; // Gauti dešimčių skaičių
text[2] = temp_whole%10 + 48; // Gauti vienetų skaičių
// Gauti kintamojo temp_fraction vienetus po kablelio
temp_fraction = temp2write << (4-RES_SHIFT); // rodo dešimtasias dalis
temp_fraction &= 0x000F;
temp_fraction *= 625;
// Paversti kintamojo temp_fraction duomenis į vienetus
text[4] = temp_fraction/1000 + 48; // Gauti vienetų skaičių po kablelio
// Išvesti temperatūra į LCD ekraną.
Lcd_Out(1, 6,text);
}
void main() {
char ROMCODE_A[] = {0x10, 0x30, 0xC5, 0xC8, 0x00, 0x00, 0x00, 0xC3};
unsigned char i;
ADCON1 = 7 ;
Lcd_Init(); // Inicializuoti LCD
Lcd_Cmd(_LCD_CLEAR); // Išvalyti LCD
Lcd_Cmd(_LCD_CURSOR_OFF); // Išjungti kursorių
Lcd_Out(1, 1, "Temp:");
// Išvedamas laipsnio ženklas ir celsijaus simbolis
Lcd_Chr(1,11,223);
Lcd_Chr(1,12,'C');
//Duomenų nuskaitymo programa
do {
//Temperatūros nuskaitymas
Ow_Reset(&PORTB, 6);
Ow_Write(&PORTB, 6,0x55);
for(i=0;i<8;i++)
{ OW_Write(&PORTB, 6, ROMCODE_A); //Master send 64 bit ROM codice <---=.
}
Ow_Write(&PORTB, 6, 0x44); // Issue command CONVERT_T
Delay_us(600);
Ow_Reset(&PORTB, 6);
Ow_Write(&PORTB, 6,0x55);
for(i=0;i<8;i++)
{ OW_Write(&PORTB, 6, ROMCODE_A); //Master send 64 bit ROM codice <---=.
}
Ow_Write(&PORTB, 6, 0xBE);
temp = Ow_Read(&PORTB, 6);
temp = (Ow_Read(&PORTB, 6) << + temp;
//--- Format and display result on Lcd
Display_Temp(temp);
Delay_ms(120);
} while (1);
}
I don't know how to use MATCH_ROM, that I could read my device. can anyone help me?
// LCD ekrano prijungimai
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
char ROMCODE_A [8] = {0x10, 0x30, 0xC5, 0xC8, 0x00, 0x00, 0x00, 0xC3};
char ROMCODE_B [8] = {0xF4, 0x00, 0x00, 0x00,0xC8, 0xC5, 0x31, 0x10};
const unsigned short TEMP_RESOLUTION = 9;// nustatomas konstantos tipas ir sensoriaus tipas
char *text = "000.0"; //nustatomas kintamojo tipas ir pradinė jo reikšmė
unsigned temp; //kintamasis temperatūros nuskaitymui
void Display_Temp(unsigned int temp2write) {
const unsigned short RES_SHIFT = TEMP_RESOLUTION - 8; //priklauso nuo sensoriaus rezoliucijos
char temp_whole;
unsigned int temp_fraction;
int neigtemp = 1;
// Tikrinti ar temperatūra nėra neigiama
if (temp2write & 0x8000) {
text[0] = '-';
temp2write = ~temp2write + 1;
neigtemp=1;
}
else {
neigtemp=0;
}
// gauti kintamąji temp_whole
temp_whole = temp2write >> RES_SHIFT ;
if (!neigtemp) { // tikrinti kintamajį neigtemp
if (temp_whole/100) // Perversti temp_whole į vienetus
text[0] = temp_whole/100 + 48;
else
text[0] = ' ';
}
text[1] = (temp_whole/10)%10+48; // Gauti dešimčių skaičių
text[2] = temp_whole%10 + 48; // Gauti vienetų skaičių
// Gauti kintamojo temp_fraction vienetus po kablelio
temp_fraction = temp2write << (4-RES_SHIFT); // rodo dešimtasias dalis
temp_fraction &= 0x000F;
temp_fraction *= 625;
// Paversti kintamojo temp_fraction duomenis į vienetus
text[4] = temp_fraction/1000 + 48; // Gauti vienetų skaičių po kablelio
// Išvesti temperatūra į LCD ekraną.
Lcd_Out(1, 6,text);
}
void main() {
char ROMCODE_A[] = {0x10, 0x30, 0xC5, 0xC8, 0x00, 0x00, 0x00, 0xC3};
unsigned char i;
ADCON1 = 7 ;
Lcd_Init(); // Inicializuoti LCD
Lcd_Cmd(_LCD_CLEAR); // Išvalyti LCD
Lcd_Cmd(_LCD_CURSOR_OFF); // Išjungti kursorių
Lcd_Out(1, 1, "Temp:");
// Išvedamas laipsnio ženklas ir celsijaus simbolis
Lcd_Chr(1,11,223);
Lcd_Chr(1,12,'C');
//Duomenų nuskaitymo programa
do {
//Temperatūros nuskaitymas
Ow_Reset(&PORTB, 6);
Ow_Write(&PORTB, 6,0x55);
for(i=0;i<8;i++)
{ OW_Write(&PORTB, 6, ROMCODE_A); //Master send 64 bit ROM codice <---=.
}
Ow_Write(&PORTB, 6, 0x44); // Issue command CONVERT_T
Delay_us(600);
Ow_Reset(&PORTB, 6);
Ow_Write(&PORTB, 6,0x55);
for(i=0;i<8;i++)
{ OW_Write(&PORTB, 6, ROMCODE_A); //Master send 64 bit ROM codice <---=.
}
Ow_Write(&PORTB, 6, 0xBE);
temp = Ow_Read(&PORTB, 6);
temp = (Ow_Read(&PORTB, 6) << + temp;
//--- Format and display result on Lcd
Display_Temp(temp);
Delay_ms(120);
} while (1);
}
I don't know how to use MATCH_ROM, that I could read my device. can anyone help me?
Re: Multiple DS18S20
Hi,
You may find this project helpful :
http://www.libstock.com/projects/view/3 ... ctionality
Regards,
Filip.
You may find this project helpful :
http://www.libstock.com/projects/view/3 ... ctionality
Regards,
Filip.
Re: Multiple DS18S20
Hi,
I was playing with the OneWire a bit. You can place as many OneWire device on the bus as you want. It finds arbitrary number of the devices attached to the bus and sends its ROM address to the UART. The OneWire_lib.c file is given from Dallas and modified to MikroC.
This is the OneWire_lib.c:
Bonca
I was playing with the OneWire a bit. You can place as many OneWire device on the bus as you want. It finds arbitrary number of the devices attached to the bus and sends its ROM address to the UART. The OneWire_lib.c file is given from Dallas and modified to MikroC.
Code: Select all
#include "OneWire_lib.c"
sbit ONEWIRE_DATA_READ at RC0_bit; // OneWire pin on RC0
sbit ONEWIRE_DATA_WRITE at LATC0_bit;
sbit ONEWIRE_DATA_DIRECTION at TRISC0_bit;
char to_uart[3];
char i, cnt;
void main() {
OSCCON = 0x72;
ADCON0.ADON = 0;
ADCON1 = 0x0F;
CMCON = 0x07;
TRISA = 0;
LATA = 0;
TRISB = 0;
LATB = 0;
LATC = 0;
TRISC = 0;
UART1_Init(9600);
delay_ms(100);
OneWire_Init();
while(1) {
OneWire_Init();
OneWire_FindFirstDevice();
for(i = 0; i < 7; i++){ // 0...6
ByteToHex(RomAddress[i], to_uart);
UART_Write_Text(to_uart);
UART_Write(45);
}
ByteToHex(RomAddress[7], to_uart); // 7
UART_Write_Text(to_uart);
UART_Write(13);
UART_Write(10);
delay_ms(100);
OneWire_FindNextDevice();
for(i = 0; i < 7; i++){
ByteToHex(RomAddress[i], to_uart);
UART_Write_Text(to_uart);
UART_Write(45);
}
ByteToHex(RomAddress[7], to_uart);
UART_Write_Text(to_uart);
UART_Write(13);
UART_Write(10);
delay_ms(100);
OneWire_FindNextDevice();
for(i = 0; i < 7; i++){
ByteToHex(RomAddress[i], to_uart);
UART_Write_Text(to_uart);
UART_Write(45);
}
ByteToHex(RomAddress[7], to_uart);
UART_Write_Text(to_uart);
UART_Write(13);
UART_Write(10);
delay_ms(100);
OneWire_FindNextDevice();
for(i = 0; i < 7; i++){
ByteToHex(RomAddress[i], to_uart);
UART_Write_Text(to_uart);
UART_Write(45);
}
ByteToHex(RomAddress[7], to_uart);
UART_Write_Text(to_uart);
UART_Write(13);
UART_Write(10);
delay_ms(100);
OneWire_FindNextDevice();
for(i = 0; i < 7; i++){
ByteToHex(RomAddress[i], to_uart);
UART_Write_Text(to_uart);
UART_Write(45);
}
ByteToHex(RomAddress[7], to_uart);
UART_Write_Text(to_uart);
UART_Write(13);
UART_Write(10);
delay_ms(100);
}
}
Code: Select all
/*******************************************************************************
*******************************************************************************/
#define ONEWIRE_DEVICE_ADDRESS_LENGTH 8
extern sfr sbit ONEWIRE_DATA_DIRECTION; // any port TRIS register
extern sfr sbit ONEWIRE_DATA_READ; // any port PORT register
extern sfr sbit ONEWIRE_DATA_WRITE; // any port LAT register
static char RomAddress[ONEWIRE_DEVICE_ADDRESS_LENGTH];
static char DoneFlag;
static char LastDiscrepancy;
static char FoundROM[32][8]; // Table of found ROM codes [number_of_found_ROMs][number_of_byes]
static char numROMs; // number_of_found_ROMs
static char RomBytes[8];
char OneWire_Init() { // sends reset pulse and expects presence/absence pulse
char OneWireBit;
ONEWIRE_DATA_DIRECTION = 0;
ONEWIRE_DATA_WRITE = 1; // if TRIS register init value in
delay_us(10); // the main would be 0...
ONEWIRE_DATA_WRITE = 0;
delay_us(480);
ONEWIRE_DATA_DIRECTION = 1;
ONEWIRE_DATA_WRITE = 1;
delay_us(50);
OneWireBit = ONEWIRE_DATA_READ; // presence (0 = OneWire device(s) present, 1 = no OneWire device)
delay_us(430);
return OneWireBit;
}
char OneWire_ReadBit() {
bit OneWireBit;
GIE_bit = 0; // disable interrupts during read period
ONEWIRE_DATA_DIRECTION = 0;
ONEWIRE_DATA_WRITE = 0;
delay_us(2); // bitstart delay
ONEWIRE_DATA_DIRECTION = 1;
ONEWIRE_DATA_WRITE = 1;
delay_us(10); // read delay
OneWireBit = ONEWIRE_DATA_READ;
delay_us(50); // completing the time slot to approx. 60 us
GIE_bit = 1; // enable interrupts
return (OneWireBit);
}
void OneWire_WriteBit(char OneWireBit) {
if (OneWireBit) { // write bit 1
ONEWIRE_DATA_DIRECTION = 0;
ONEWIRE_DATA_WRITE = 0;
delay_us(5); // must be between 2...15 us!!!
ONEWIRE_DATA_DIRECTION = 1; // let the pull-up resistor work
ONEWIRE_DATA_WRITE = 1; // must be high when TRIS is set as output next time
delay_us(60); // completing the time slot to approx. 60 us
}
else { // write bit 0
ONEWIRE_DATA_DIRECTION = 0;
ONEWIRE_DATA_WRITE = 0;
delay_us(60); // must be between 15...60 us!!!
ONEWIRE_DATA_DIRECTION = 1; // let the pull-up resistor work
ONEWIRE_DATA_WRITE = 1; // must be high when TRIS is set as output next time
delay_us(5); // completing the time slot to approx. 60 us
}
}
char OneWire_ReadByte() {
char i;
char value = 0;
for (i = 0; i < 8; i++) {
if (OneWire_ReadBit()) {value |= (1 << i);}
delay_us(120);
}
return(value);
}
void OneWire_WriteByte(char WriteByte) {
char i;
for (i = 0; i < 8; i++) {OneWire_WriteBit((WriteByte >> i) & 0x01);}
delay_us(105);
}
char OneWire_FindNextDevice() {
char state;
char byteindex;
char mask = 1;
char bitpos = 1;
char DiscrepancyMarker = 0;
bit bit_b;
bit StatusFlag;
bit nextBit;
// char RomAddress_to_uart[3];
for (byteindex = 0; byteindex < 8; byteindex ++) {RomAddress[byteindex] = 0x00;}
StatusFlag = OneWire_Init(); // reset the OneWire, insted of Ow_Reset(&PORTC, 0);
if (StatusFlag || DoneFlag) { // no device found
LastDiscrepancy = 0; // reset the search
return 0;
}
OneWire_WriteByte(0xF0); // send Search ROM command
byteindex = 0;
do {
state = 0;
if (OneWire_ReadBit() != 0) {state = 2;} // read bit
delay_us(120);
if (OneWire_ReadBit() != 0) {state |= 1;} // read bit complement
delay_us(120);
/* state = 0bxxxxxx00 There are devices connected to the bus which have conflicting bits in the current ROM code bit position
state = 0bxxxxxx01 All devices connected to the bus have a 0 in this bit position
state = 0bxxxxxx10 All devices connected to the bus have a 1 in this bit position
state = 0bxxxxxx11 There are no devices connected to the 1-wire bus */
if (state == 3) {break;} // if there are no devices on the bus
else {
if (state > 0) { // devices have the same logical value at this position
bit_b = state >> 1; // get bit value
}
else { // devices have confilcting bits in the current ROM code
if (bitpos < LastDiscrepancy) { // if there was a conflict on the last iteration
bit_b = ((RomAddress[byteindex] & mask) > 0); // take same bit as in last iteration
}
else {bit_b = (bitpos == LastDiscrepancy);}
if (bit_b == 0) {DiscrepancyMarker = bitpos;}
}
if (bit_b != 0) {
RomAddress[byteindex] |= mask; // store bit in ROM address
}
else {RomAddress[byteindex] &= ~mask;}
OneWire_WriteBit(bit_b); // increment bit position
bitpos++;
mask = mask << 1; // calculate next mask value
if (mask == 0) { // check if this byte has finished
byteindex ++; // advance to next byte of ROM mask
mask = 1; // update mask
}
}
} while(byteindex < ONEWIRE_DEVICE_ADDRESS_LENGTH);
if (bitpos < 65) {LastDiscrepancy = 0;} // if search was unsuccessful then reset the last discrepancy to 0
else { // search was successful
LastDiscrepancy = DiscrepancyMarker;
DoneFlag = (LastDiscrepancy == 0);
nextBit = 1; // indicates search is not complete yet, more parts remain
}
return nextBit;
}
char OneWire_FindFirstDevice() {
LastDiscrepancy = 0;
DoneFlag = 0;
return (OneWire_FindNextDevice());
}
char OneWire_FindAllDevice() {
char m, cont = 0;
if(!OneWire_Init()) {
if(OneWire_FindFirstDevice()) { // Begins when at least one part found
numROMs = 0;
do {
numROMs++;
cont++;
for (m = 0; m < 8; m++) {
FoundROM[numROMs][m] = RomBytes[m];
}
} while (OneWire_FindNextDevice()); // Continues until no additional
}
}
return cont;
}
Re: Multiple DS18S20
Thank you very much for the answers. I know how to read ROM addresses, but I want write on LCD all devices temperature.
Re: Multiple DS18S20
Thank you Bonca for source codeBonca wrote:Hi,
I was playing with the OneWire a bit. You can place as many OneWire device on the bus as you want. It finds arbitrary number of the devices attached to the bus and sends its ROM address to the UART. The OneWire_lib.c file is given from Dallas and modified to MikroC.This is the OneWire_lib.c:Code: Select all
#include "OneWire_lib.c" sbit ONEWIRE_DATA_READ at RC0_bit; // OneWire pin on RC0 sbit ONEWIRE_DATA_WRITE at LATC0_bit; sbit ONEWIRE_DATA_DIRECTION at TRISC0_bit; char to_uart[3]; char i, cnt; void main() { OSCCON = 0x72; ADCON0.ADON = 0; ADCON1 = 0x0F; CMCON = 0x07; TRISA = 0; LATA = 0; TRISB = 0; LATB = 0; LATC = 0; TRISC = 0; UART1_Init(9600); delay_ms(100); OneWire_Init(); while(1) { OneWire_Init(); OneWire_FindFirstDevice(); for(i = 0; i < 7; i++){ // 0...6 ByteToHex(RomAddress[i], to_uart); UART_Write_Text(to_uart); UART_Write(45); } ByteToHex(RomAddress[7], to_uart); // 7 UART_Write_Text(to_uart); UART_Write(13); UART_Write(10); delay_ms(100); OneWire_FindNextDevice(); for(i = 0; i < 7; i++){ ByteToHex(RomAddress[i], to_uart); UART_Write_Text(to_uart); UART_Write(45); } ByteToHex(RomAddress[7], to_uart); UART_Write_Text(to_uart); UART_Write(13); UART_Write(10); delay_ms(100); OneWire_FindNextDevice(); for(i = 0; i < 7; i++){ ByteToHex(RomAddress[i], to_uart); UART_Write_Text(to_uart); UART_Write(45); } ByteToHex(RomAddress[7], to_uart); UART_Write_Text(to_uart); UART_Write(13); UART_Write(10); delay_ms(100); OneWire_FindNextDevice(); for(i = 0; i < 7; i++){ ByteToHex(RomAddress[i], to_uart); UART_Write_Text(to_uart); UART_Write(45); } ByteToHex(RomAddress[7], to_uart); UART_Write_Text(to_uart); UART_Write(13); UART_Write(10); delay_ms(100); OneWire_FindNextDevice(); for(i = 0; i < 7; i++){ ByteToHex(RomAddress[i], to_uart); UART_Write_Text(to_uart); UART_Write(45); } ByteToHex(RomAddress[7], to_uart); UART_Write_Text(to_uart); UART_Write(13); UART_Write(10); delay_ms(100); } }
BoncaCode: Select all
/******************************************************************************* *******************************************************************************/ #define ONEWIRE_DEVICE_ADDRESS_LENGTH 8 extern sfr sbit ONEWIRE_DATA_DIRECTION; // any port TRIS register extern sfr sbit ONEWIRE_DATA_READ; // any port PORT register extern sfr sbit ONEWIRE_DATA_WRITE; // any port LAT register static char RomAddress[ONEWIRE_DEVICE_ADDRESS_LENGTH]; static char DoneFlag; static char LastDiscrepancy; static char FoundROM[32][8]; // Table of found ROM codes [number_of_found_ROMs][number_of_byes] static char numROMs; // number_of_found_ROMs static char RomBytes[8]; char OneWire_Init() { // sends reset pulse and expects presence/absence pulse char OneWireBit; ONEWIRE_DATA_DIRECTION = 0; ONEWIRE_DATA_WRITE = 1; // if TRIS register init value in delay_us(10); // the main would be 0... ONEWIRE_DATA_WRITE = 0; delay_us(480); ONEWIRE_DATA_DIRECTION = 1; ONEWIRE_DATA_WRITE = 1; delay_us(50); OneWireBit = ONEWIRE_DATA_READ; // presence (0 = OneWire device(s) present, 1 = no OneWire device) delay_us(430); return OneWireBit; } char OneWire_ReadBit() { bit OneWireBit; GIE_bit = 0; // disable interrupts during read period ONEWIRE_DATA_DIRECTION = 0; ONEWIRE_DATA_WRITE = 0; delay_us(2); // bitstart delay ONEWIRE_DATA_DIRECTION = 1; ONEWIRE_DATA_WRITE = 1; delay_us(10); // read delay OneWireBit = ONEWIRE_DATA_READ; delay_us(50); // completing the time slot to approx. 60 us GIE_bit = 1; // enable interrupts return (OneWireBit); } void OneWire_WriteBit(char OneWireBit) { if (OneWireBit) { // write bit 1 ONEWIRE_DATA_DIRECTION = 0; ONEWIRE_DATA_WRITE = 0; delay_us(5); // must be between 2...15 us!!! ONEWIRE_DATA_DIRECTION = 1; // let the pull-up resistor work ONEWIRE_DATA_WRITE = 1; // must be high when TRIS is set as output next time delay_us(60); // completing the time slot to approx. 60 us } else { // write bit 0 ONEWIRE_DATA_DIRECTION = 0; ONEWIRE_DATA_WRITE = 0; delay_us(60); // must be between 15...60 us!!! ONEWIRE_DATA_DIRECTION = 1; // let the pull-up resistor work ONEWIRE_DATA_WRITE = 1; // must be high when TRIS is set as output next time delay_us(5); // completing the time slot to approx. 60 us } } char OneWire_ReadByte() { char i; char value = 0; for (i = 0; i < 8; i++) { if (OneWire_ReadBit()) {value |= (1 << i);} delay_us(120); } return(value); } void OneWire_WriteByte(char WriteByte) { char i; for (i = 0; i < 8; i++) {OneWire_WriteBit((WriteByte >> i) & 0x01);} delay_us(105); } char OneWire_FindNextDevice() { char state; char byteindex; char mask = 1; char bitpos = 1; char DiscrepancyMarker = 0; bit bit_b; bit StatusFlag; bit nextBit; // char RomAddress_to_uart[3]; for (byteindex = 0; byteindex < 8; byteindex ++) {RomAddress[byteindex] = 0x00;} StatusFlag = OneWire_Init(); // reset the OneWire, insted of Ow_Reset(&PORTC, 0); if (StatusFlag || DoneFlag) { // no device found LastDiscrepancy = 0; // reset the search return 0; } OneWire_WriteByte(0xF0); // send Search ROM command byteindex = 0; do { state = 0; if (OneWire_ReadBit() != 0) {state = 2;} // read bit delay_us(120); if (OneWire_ReadBit() != 0) {state |= 1;} // read bit complement delay_us(120); /* state = 0bxxxxxx00 There are devices connected to the bus which have conflicting bits in the current ROM code bit position state = 0bxxxxxx01 All devices connected to the bus have a 0 in this bit position state = 0bxxxxxx10 All devices connected to the bus have a 1 in this bit position state = 0bxxxxxx11 There are no devices connected to the 1-wire bus */ if (state == 3) {break;} // if there are no devices on the bus else { if (state > 0) { // devices have the same logical value at this position bit_b = state >> 1; // get bit value } else { // devices have confilcting bits in the current ROM code if (bitpos < LastDiscrepancy) { // if there was a conflict on the last iteration bit_b = ((RomAddress[byteindex] & mask) > 0); // take same bit as in last iteration } else {bit_b = (bitpos == LastDiscrepancy);} if (bit_b == 0) {DiscrepancyMarker = bitpos;} } if (bit_b != 0) { RomAddress[byteindex] |= mask; // store bit in ROM address } else {RomAddress[byteindex] &= ~mask;} OneWire_WriteBit(bit_b); // increment bit position bitpos++; mask = mask << 1; // calculate next mask value if (mask == 0) { // check if this byte has finished byteindex ++; // advance to next byte of ROM mask mask = 1; // update mask } } } while(byteindex < ONEWIRE_DEVICE_ADDRESS_LENGTH); if (bitpos < 65) {LastDiscrepancy = 0;} // if search was unsuccessful then reset the last discrepancy to 0 else { // search was successful LastDiscrepancy = DiscrepancyMarker; DoneFlag = (LastDiscrepancy == 0); nextBit = 1; // indicates search is not complete yet, more parts remain } return nextBit; } char OneWire_FindFirstDevice() { LastDiscrepancy = 0; DoneFlag = 0; return (OneWire_FindNextDevice()); } char OneWire_FindAllDevice() { char m, cont = 0; if(!OneWire_Init()) { if(OneWire_FindFirstDevice()) { // Begins when at least one part found numROMs = 0; do { numROMs++; cont++; for (m = 0; m < 8; m++) { FoundROM[numROMs][m] = RomBytes[m]; } } while (OneWire_FindNextDevice()); // Continues until no additional } } return cont; }
Re: Multiple DS18S20
Hello,
Bonca maybe you can share all project files with proteus dsn?
Thank you
Regards,
Pranas
Bonca maybe you can share all project files with proteus dsn?
Thank you
Regards,
Pranas
Re: Multiple DS18S20
Hello,
Filip you recomended library is in pascal and basic. This is mikroc topic.
I have tried Bonca source code and have few problems.
Your code runs but if use OneWire_FindAllDevide it is not working or something i cant understand.
Function defines that 3 sensors on network but addresses is 00.
All project with proteus files here http://infoside.lt/~pranas/mikroe/DS18B20_search.zip
Filip you recomended library is in pascal and basic. This is mikroc topic.
I have tried Bonca source code and have few problems.
Your code runs but if use OneWire_FindAllDevide it is not working or something i cant understand.
Function defines that 3 sensors on network but addresses is 00.
Code: Select all
#include "OneWire_lib.h"
sbit ONEWIRE_DATA_READ at RC0_bit; // OneWire pin on RC0
sbit ONEWIRE_DATA_WRITE at LATC0_bit;
sbit ONEWIRE_DATA_DIRECTION at TRISC0_bit;
char to_uart[3];
char i, j;
void main()
{
OSCCON = 0x72;
ADCON0.ADON = 0;
ADCON1 = 0x0F;
CMCON = 0x07;
TRISA = 0;
LATA = 0;
TRISB = 0;
LATB = 0;
LATC = 0;
TRISC = 0;
UART1_Init(9600);
delay_ms(100);
OneWire_FindAllDevices();
delay_ms(100);
if (numROMs==0)
{
UART_Write_Text("No sensors found");
}
else
{
for(i = 0; i < numROMs; i++)
{
UART_Write_Text("Sensor[");
ByteToHex(i, to_uart);
UART_Write_Text(to_uart);
UART_Write_Text("]: ");
for(j = 0; j < 7; j++)
{
ByteToHex(FoundROM[i][j], to_uart);
UART_Write_Text(to_uart);
UART_Write(45);
}
ByteToHex(FoundROM[i][7], to_uart);
UART_Write_Text(to_uart);
UART_Write(13);
UART_Write(10);
delay_ms(100);
}//end for i
}//end else
}
All project with proteus files here http://infoside.lt/~pranas/mikroe/DS18B20_search.zip
Re: Multiple DS18S20
Hi,
Regards,
Filip.
I am aware that this is a mikroC topic, I said only that this project may be useful.Filip you recomended library is in pascal and basic. This is mikroc topic.
Regards,
Filip.
Re: Multiple DS18S20
Code: Select all
char ROMCODE_A [8] = {0x10, 0x30, 0xC5, 0xC8, 0x00, 0x00, 0x00, 0xC3};
char ROMCODE_B [8] = {0xF4, 0x00, 0x00, 0x00,0xC8, 0xC5, 0x31, 0x10};
Romcode A seems indeed to be from a DS18S20 (CRC is Ok, is checked), but RomCode B is certainly wrong: byte 0 should be $10! Perhaps the bytes are mirrored in Romcode B?
Byte 0 of the romcode denotes the "family":
0x10 for a DS1820 or DS18S20
0x28 for a DS18B20
0xF4 is certainly not a DS18x20 device!.
Also: temperature conversion takes 750 milliseconds, not 600 microseconds:
Code: Select all
Ow_Write(&PORTB, 6, 0x44); // Issue command CONVERT_T
Delay_us(600); // should be delay_ms(750)
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)
Re: Multiple DS18S20
Does anybody got onewire search with mikroc?
Regards
Pranas
Regards
Pranas
Re: Multiple DS18S20
Perhaps here: http://www.mikroe.com/forum/viewtopic.p ... it=+search?prancius wrote:Does anybody got onewire search with mikroc?
Regards
Pranas
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)
Re: Multiple DS18S20
Check out this:
http://www.libstock.com/projects/view/1 ... pic-eeprom
It will show you how to read and use the unique ID from the device.
http://www.libstock.com/projects/view/1 ... pic-eeprom
It will show you how to read and use the unique ID from the device.
Re: Multiple DS18S20
Hello,
OneWire search is working with proteus on PIC18F2520.
Any ideas why it not working correctlly in LV18F board with PIC18J87J60.
I cant determine end off loop
it reads adresses but x allways == 1 and ever goes out from loop.
x at the end of search should be 0 but ...
Regards,
Pranas
OneWire search is working with proteus on PIC18F2520.
Any ideas why it not working correctlly in LV18F board with PIC18J87J60.
I cant determine end off loop
Code: Select all
....
while (1)
{
x=OneWire_FindNextDevice();
if (x==0) break;
}
....
x at the end of search should be 0 but ...
Regards,
Pranas
Re: Multiple DS18S20
I have tested with EASYPIC4 and PIC188F2520 it is working good.
So there is some problem in REGISTER config.
Project here http://infoside.lt/~pranas/OneWire_sear ... orking.rar
Does mikroe support works?
So there is some problem in REGISTER config.
Project here http://infoside.lt/~pranas/OneWire_sear ... orking.rar
Does mikroe support works?
Re: Multiple DS18S20
Hi,
The mikroE supports works, but as far as I can see you are using a library/example that is developed by a user, not mikroE, so this is out of our support scope.
Thank you for the understanding.
Regards,
Filip.
The mikroE supports works, but as far as I can see you are using a library/example that is developed by a user, not mikroE, so this is out of our support scope.
Thank you for the understanding.
Regards,
Filip.