I've got a board with a Pic16F18854 and a DS2411 OW device. There's a 1k8 pullup resistor on the data line and eventually I'll add new devices but for now just a single device.
When I call OWreset() it returns a presence pulse so I then send a ReadRom (0x33) command to read the ROM but only get back 0xffs indicating that the device isn't responding.
Here's the code I'm using,
The relevant parts of OW.h are,
Can anyone see what I'm doing wrong here? I'm sure it's something stupid but can't see it.
Thanks,
Mike.
Edit, I've checked that the pin goes low after assertLow() and goes high again after release().
When I call OWreset() it returns a presence pulse so I then send a ReadRom (0x33) command to read the ROM but only get back 0xffs indicating that the device isn't responding.
Here's the code I'm using,
Code:
//the calling code is,
OWinit();
uint8_t presence=OWreset();
OWwriteByte(0x33);
uint8_t ROM[8];
for(uint8_t i=0;i<8;i++){
ROM[i]=OWreadByte();
}
//and the One Wire code,
#include "OW.h"
inline void assertLow(){
OWpin_W=0; //ensure low
OWtris=0; //make output
}
inline void release(){
OWtris=1; //make input
}
void OWinit(void){
OWtris=1; //shouldn't be needed
}
//Send byte LSBit first
void OWwriteByte(uint8_t dat){
for(uint8_t i=0;i<8;i++){
OWwriteBit(dat&1);
dat>>=1;
}
}
//read byte LSBit first
uint8_t OWreadByte(){
uint8_t dat=1;
for(uint8_t i=0;i<8;i++){
dat>>=1;
if(OWreadBit())
dat|=0x80;
}
return(dat);
}
uint8_t OWreset(void){
assertLow();
__delay_us(560);
release();
__delay_us(67);
uint8_t temp=OWpin_R;
__delay_us(60);
return(temp);
}
void OWwriteBit(uint8_t dat){
assertLow();
if(dat)
__delay_us(6);
else
__delay_us(58);
release();
if(dat)
__delay_us(58);
else
__delay_us(6);
}
uint8_t OWreadBit(){
assertLow();
__delay_us(5);
release();
__delay_us(7);
uint8_t temp=OWpin_R;
__delay_us(52);
return(temp);
}
Code:
#define OWpin_R PORTCbits.RC5
#define OWpin_W LATCbits.LATC5
#define OWtris TRISCbits.TRISC5
Can anyone see what I'm doing wrong here? I'm sure it's something stupid but can't see it.
Thanks,
Mike.
Edit, I've checked that the pin goes low after assertLow() and goes high again after release().