Hello,
I'm trying to integrate the 1-wire protocol on the cc2640r2f micro-controller for the temperature sensor ds18b20.
I have gone through many of the forum posts and checked that the protocol needs to built using pin or gpio driver .
So with the Maxim integrated application note I have written the below code but i'm not able to get the required output.
uint8_t owire_reset(void) { uint8_t result; vOutputMode(); //DELAY_US(0); usleep(0); PIN_setPortOutputValue(hDqPin,board_low); //DELAY_US(480); usleep(480); PIN_setPortOutputValue(hDqPin,board_high); //delay_us(70); usleep(70); vInputMode(); result=PIN_getInputValue(Board_I2C0_SDA1_ext);//^0x01; //delay_us(410); usleep(410); return result; } void ow_write_bit(char bit_1) { vOutputMode(); PIN_setPortOutputValue(hDqPin,board_low); //delay_us(60); if(bit_1==1) PIN_setPortOutputValue(hDqPin,board_high); usleep(104); PIN_setPortOutputValue(hDqPin,board_high); } uint8_t ow_read_bit(void) { uint8_t result; vOutputMode(); PIN_setPortOutputValue(hDqPin,board_low); //delay_us(6); //usleep(6); PIN_setPortOutputValue(hDqPin,board_high); //delay_us(9); usleep(15); vInputMode(); result=PIN_getInputValue(Board_I2C0_SDA1_ext);// & 0x01; //delay_us(55); //usleep(55); return result; } void ow_write_byte(char data2) { uint8_t loop,temp; for(loop=0;loop<8;loop++) { temp = data2>>loop; temp &= 0x01; ow_write_bit(temp); } usleep(104); } uint8_t ow_read_byte(void) { uint8_t loop,result=0; for (loop = 0; loop < 8; loop++) { if (ow_read_bit()) result |= 0x01<<loop; usleep(120); } return result; } void read_ext_temp(void) { char get[10]; uint8_t k; owire_reset(); ow_write_byte(0xCC); ow_write_byte(0x44); usleep(104); owire_reset(); ow_write_byte(0xCC); ow_write_byte(0xBE); for(k=0;k<9;k++) get[k]=ow_read_byte(); temp_msb=get[1]; temp_lsb=get[0]; if(temp_msb<=0x80) temp_lsb=temp_lsb/2; temp_msb=temp_msb & 0x80; if(temp_msb>=0x80) temp_lsb=(~temp_lsb)+1; if(temp_msb>=0x80) temp_lsb=temp_lsb/2; if(temp_msb>=0x80) temp_lsb=((-1)*temp_lsb); temp_c=temp_lsb; //temp_f=(((int)temp_c)*9)/5+32; } void read_romcode(void) { uint8_t n; owire_reset(); ow_write_byte(0x33); for(n=0;n<8;n++) dat[n]=ow_read_byte(); } void vOutputMode(void) { PIN_close(hDqPin); hDqPin = PIN_open(&pinState, GPIO_OutLine); // GPIO_setConfig(Board_I2C0_SDA1_ext, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_OD_PU); } void vInputMode(void) { PIN_close(hGpioPin); hDqPin = PIN_open(&pinState, GPIO_InLine); // GPIO_setConfig(Board_I2C0_SDA1_ext, GPIO_CFG_INPUT | GPIO_CFG_IN_PD); } PIN_Config GPIO_OutLine[] = { Board_I2C0_SDA1_ext | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_INPUT_DIS | PIN_OPENDRAIN, /* DQ line initially off */ PIN_TERMINATE /* Terminate list */ }; PIN_Config GPIO_InLine[] = { Board_I2C0_SDA1_ext | PIN_INPUT_EN | PIN_PULLUP | PIN_GPIO_OUTPUT_DIS | PIN_HYSTERESIS, PIN_TERMINATE /* Terminate list */ };
Can anybody help me with this issue.
Is it due to the micro-second delay or somewhere I'm going wrong.
Thanks.