This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

implement one wire protocol on cc3200

Other Parts Discussed in Thread: CC3200

Hi everyone,

I'm trying to interface a temperature sensor DS18B20.

There is a way to implement one wire protocol to cc3200?

There is already an implementation? 

Thanks in advance.

  • We don't have an implementation - I'll have to study more on the protocol, and do few experiments (on CC3200) before making any suggestions.

    -/Praneet
  • Hi,
    thanks for your answer. I'm studying the protocol and I can detect the presence of temperature sensor as described in the datasheet.
    But when I try to send commands to sensor, it doesn't give me a response. I suspect that the problem is in the timing. I'm using the UtilsDelay to implement the wait, but I've read that if the delay isn't accurate the sensor doesn't respond. Is there a library or a specific function to implement the wait?
  • Hi,

    I use 1-wire devices for long time. 1-wire bus is time driven and from these reason is communication in os-based environment complicated. Best way how to achieve precision timing in bus is disable interrupts before bit reading/writing. But this behaviour can complicate your application multitasking.
    My suggestion is to use 1-wire bus master (e.g. DS2482).


    Regards,
    Jan
  • Hi,

    I want understand if is my code wrong

    //this code write 1 or 0 on 1-wire bus

    //it takes the bit as parameter

    void write_bit(unsigned short bit){
    
    
    GPIODirModeSet(GPIOA0_BASE, 0x8, GPIO_DIR_MODE_OUT);
    PinConfigSet(PIN_58, PIN_STRENGTH_2MA|PIN_STRENGTH_6MA, PIN_TYPE_STD);
    
    GPIO_IF_Set(3, g_uport, g_upin, 1);
    
    UtilsDelay((3*80)/3);
    
    GPIO_IF_Set(3, g_uport, g_upin, 0);
    
    
    if(bit==0){
    //must be 0 for 60 usec
    UtilsDelay(60*80);
    
    
    
    }
    else{
    
    //must be to 0 for 1 usec
    UtilsDelay((3*80)/3);
    
    }
    
    GPIO_IF_Set(3, g_uport, g_upin, 1);
    
    GPIODirModeSet(GPIOA0_BASE, 0x8, GPIO_DIR_MODE_IN);
    PinConfigSet(PIN_58, PIN_STRENGTH_2MA|PIN_STRENGTH_6MA, PIN_TYPE_OD_PU);
    
    if(bit==0){
    //must be 0 for 60 usec
    UtilsDelay((3*80)/3);
    
    
    
    }
    else{
    
    //must be 0 for 1 usec
    UtilsDelay(60*80);
    
    }
    
    
    }

  • Another things that I've read from datasheet is that I must use the Read Scratchpad to read temperature, after make Convert T request and after reset the bus. Now, I perform the Convert T command after I make Skip Rom command and I ask me if it's possible make Read scratchpad command after Skip rom command?
    I've tried but it doesn't work. Where is the error?
  • For accurate delay, you could use CC3200's GPT and make the application wait till the timer expires.

    -/Praneet
  • 
    

    Hi,

    I've modified my code to use a timer

    in the main thread I set




    MAP_PRCMPeripheralClkEnable(PRCM_TIMERA0, PRCM_RUN_MODE_CLK); MAP_PRCMPeripheralReset(PRCM_TIMERA0); MAP_TimerConfigure(TIMERA0_BASE,TIMER_CFG_ONE_SHOT); MAP_TimerPrescaleSet(TIMERA0_BASE,TIMER_A,0); Timer_IF_IntSetup(TIMERA0_BASE, TIMER_A, handletimer); GPIO_IF_GetPortNPin(3, &g_uportauscita, &g_upinuscita); set_output(); //set output line to high GPIO_IF_Set(3, g_uport, g_upin, 1); UtilsDelay((10*80)/3); MAP_TimerLoadSet(TIMERA0_BASE,TIMER_A,(8000000/1000000)*(1)); GPIO_IF_Set(3, g_uportauscita, g_upinuscita, 0); MAP_TimerEnable(TIMERA0_BASE,TIMER_A); In the handler the code Semaphore_pend(sem,BIOS_WAIT_FOREVER); //UART_PRINT("Overflow\n\r"); if(counter_phases==0){ if(counter_tick_GPT<480){ GPIO_IF_Set(3, g_uport, g_upin, 0); //the timer count every 1 usec MAP_TimerLoadSet(TIMERA0_BASE,TIMER_A,(80000000/1000000)*(1)); MAP_TimerEnable(TIMERA0_BASE,TIMER_A); contatore_tick_GPT++; } else{ GPIO_IF_Set(3, g_uport, g_upin, 1); MAP_TimerLoadSet(TIMERA0_BASE,TIMER_A,(80000000/1000000)*(1)); MAP_TimerEnable(TIMERA0_BASE,TIMER_A); set_input(); counter_tick_GPT=0; counter_phasis=2; } } else if(counter_phasis==1){ set_input(); //incremento il contatore_fasi counter_phases=2; counter_tick_GPT=0; MAP_TimerLoadSet(TIMERA0_BASE,TIMER_A,(80000000/1000000)*(1)); MAP_TimerEnable(TIMERA0_BASE,TIMER_A); } else if(counter_phasis==2){ v = GPIO_IF_Get(3, g_uport, g_upin); if(counter_tick_GPT<10){ MAP_TimerLoadSet(TIMERA0_BASE,TIMER_A,(80000000/1000000)*(1)); MAP_TimerEnable(TIMERA0_BASE,TIMER_A); counter_tick_GPT++; } else if((counter_tick_GPT>=10)&&(counter_tick_GPT<240)){ MAP_TimerLoadSet(TIMERA0_BASE,TIMER_A,(80000000/1000000)*(1)); MAP_TimerEnable(TIMERA0_BASE,TIMER_A); counter_tick_GPT++; } }
    Semaphore_post(sem);

    But after 15 usec from I set the output to high the sensor sets the bus to low only for 1 usec and not for 60 - 240 usecs. 

    Are the timer load sets wrong?

    I've considered that MCU frequency is 80Mhz

    then to count 1 usec the time to count is (80000000/1000000)*(usecs)

  • Hi,
    can you give me an information about One-wire?

    I issue a skip ROM first of ask Read Scratchpad. Is correct or I need the Rom code of one-wire device?
    I've only one device on 1-wire bus.
  • Hi,

    If there is only one 1-wire device at bus, you can use skip ROM command. For multiple devices you need send ROM code.


    Regards,
    Jan
  • 
    

    I have only one 1-wire device on the bus.

    I'm using this function to read from bus when I ask to read scratchpad




    unsigned char read_bit(void) { unsigned char v; // Get port / pin addys unsigned int addr; unsigned char pin; GPIO_IF_GetPortNPin(0, &addr, &pin); osi_EnterCritical(); // Mode Out output_mode(); // Pull Line low to start timeslot GPIO_IF_Set(0, addr, pin, 0); UtilsDelay((3*80)/3); // Pull Line high GPIO_IF_Set(0, addr, pin, 1); // Mode In input_mode(); // Delay 15usec //UtilsDelay((15*80)/3); UtilsDelay((10*80)/3); // read value v = GPIO_IF_Get(0, addr, pin); osi_ExitCritical(0); // end of timeslot UtilsDelay((53*80)/3); // return value of DQ line return(v); }

    but I read only High value on the bus. It's a UtilsDelay time issue?

    Thanks for help :D