Dear Quactel forum,
Thank you for all nice question&answers on the forum. Forum is really helpful.
I will ask on behalf of our school and research team a few questions regarding Quactel BC66 chip general purpose I/O pins (GPIOs). Development environment is Platform IO and we are using OpenCPU libraries.
We have try to connect Dallas Semicoductor DS18B20 temperature sensor directly to the GPIO pins. We have managed to toggle GPIOs with simple on and off code. And it seems to work with blinking LED (and measured with volt meter). However, we have recognise that the GPIO signal is not stabile. It’s switching randomly even we do nothing. This inconvenience makes errors between CPU and temperature sensor and readings are random.
We have tried switch off all power savings / sleep modes. We have also tried example: (https://github.com/Wiz-IO/platformio-quectel-examples/blob/master/BC66_SDK/OpenCPU/example_gpio.c) which works fine.
Temperature sensor circuit works on Arduino development board. So, all connections are done properly and there are 4,7kOhm resistor.
Please, see below the simple sample code where we just toggle GPIO pin which is used to reset temperature sensor.
Questions:
- Is this behaviour something that someone other has recognised?
- Any suggestions how to setup correctly the pins and how to avoid this kind of random switching?
- For OpenGPU is there similar Arduino functions available as pinMode(), digitalRead() and digitalWrite()?
- Is there available official library for Dallas temperature sensors on BC66 environment? (we have used our own tweaked from Arduino library)
Example code:
See the simplified version of the code we are trying to use. The ow_reset() function is copied from the datasheet (https://pdfserv.maximintegrated.com/en/an/AN162.pdf) with “DQ” lines replaced with functions found in ql_gpio.h (original datasheet lines in /* */ comments). The circuit is as shown in https://create.arduino.cc/projecthub/TheGadgetBoy/ds18b20-digital-temperature-sensor-and-arduino-9cc806 with data pin connected to GPIO1/P26 pin on the olimex dev board. The power for olimex is provided using the USB-connector (laptop PC).
void proc_main_task(s32 taskId) {
/* UART register & open, timer register … */
Ql_SleepDisable();
Ql_GPIO_Init(PINNAME_GPIO1, PINDIRECTION_OUT, PINLEVEL_LOW, PINPULLSEL_PULLUP); // can be PINDIRECTION_IN, PINLEVEL_HIGH, PINPULLSEL_DOWN, etc… does not seem to matter much in practice
Ql_Timer_Start(TIMER_ID_USER_START + 2, 5000, TRUE); // timer that calls a callback function, which currently only calls ow_reset()
while(true){Ql_OS_GetMessage(&msg);} // loop calling Ql_OS_GetMessage( … )
}
static unsigned char ow_reset(void)
{
unsigned char presence;
Ql_GPIO_SetDirection(PINNAME_GPIO1, PINDIRECTION_OUT);
/* DQ = 0; //pull DQ line low */
Ql_GPIO_SetLevel(PINNAME_GPIO1, PINLEVEL_LOW);
/* delay(29); // leave it low for 480us */
Ql_Delay_us(480);
/* DQ = 1; // allow line to return high */
Ql_GPIO_SetDirection(PINNAME_GPIO1, PINDIRECTION_IN);
// Ql_Delay_us(30); APP_DEBUG("%d\n", Ql_GPIO_GetLevel(PINNAME_GPIO1)); // wait 30us to see what happens. In general, returns 1, but also randomly 0
/* delay(3); // wait for presence */
Ql_Delay_us(72);
/* presence = DQ; // get presence signal */
presence = Ql_GPIO_GetLevel(PINNAME_GPIO1);
APP_DEBUG("Presence was %d\n", presence); // sometimes this is not 0 for unknown reasons
/* delay(25); // wait for end of timeslot */
Ql_Delay_us(448);
return (presence); // presence signal returned
} // 0=presence, 1 = no part