Hello everyone
I’m having some truble interfacing M66 with Ds18b20.
the Data pin of the sensor is connected to pin no.33 PCM_CLK.
Here is the library I use : https://github.com/dword1511/onewire-over-uart
the PCB :
the program :
**************************/
#ifdef CUSTOMER_CODE
#include “custom_feature_def.h”
#include “ql_type.h”
#include “ql_stdlib.h”
#include “ql_uart.h”
#include “ril.h”
#include <stdint.h>
#include <stddef.h>
#include “ql_gpio.h”
#include “ql_error.h”
#include “ql_timer.h”
#include “ql_power.h”
#include “ril_telephony.h”
#include “onewire.h”
#include “devices/ds18x20.h”
#include “devices/ds18x20.c”
#include “devices/common.h”
#include “devices/common.c”
char *get_type_by_id(uint8_t id)
{
switch (id)
{
case DS18S20_FAMILY_CODE:
return “DS18S20”;
case DS18B20_FAMILY_CODE:
return “DS18B20”;
case DS1822_FAMILY_CODE:
return “DS1822”;
default:
return “unknown”;
}
}
#define DEBUG_ENABLE 1
#if DEBUG_ENABLE > 0
#define DEBUG_PORT UART_PORT1
Enum_PinName Tempreture = PINNAME_PCM_CLK;
#define UART_PORT Tempreture
#define DBG_BUF_LEN 512
static char DBG_BUFFER[DBG_BUF_LEN];
#define APP_DEBUG(FORMAT,…) {
Ql_memset(DBG_BUFFER, 0, DBG_BUF_LEN);
Ql_sprintf(DBG_BUFFER,FORMAT,##VA_ARGS);
if (UART_PORT2 == (DEBUG_PORT))
{
Ql_Debug_Trace(DBG_BUFFER);
} else {
Ql_UART_Write((Enum_SerialPort)(DEBUG_PORT), (u8*)(DBG_BUFFER), Ql_strlen((const char *)(DBG_BUFFER)));
}
}
#else
#define APP_DEBUG(FORMAT,…)
#endif
#define SERIAL_RX_BUFFER_LEN 2048
// Define the UART port and the receive data buffer
static Enum_SerialPort m_myUartPort = UART_PORT1;
static u8 m_RxBuf_Uart1[SERIAL_RX_BUFFER_LEN];
static void CallBack_UART_Hdlr(Enum_SerialPort port, Enum_UARTEventType msg, bool level, void* customizedPara);
static s32 ATResponse_Handler(char* line, u32 len, void* userData);
/**
-
List sensors, from https://github.com/dword1511/onewire-over-uart
*/
static void list_sensors(void)
{
uint8_t id[OW_ROMCODE_SIZE];
uint8_t c = 0, diff = OW_SEARCH_FIRST;
int16_t temp_dc;while (diff != OW_LAST_DEVICE)
{
APP_DEBUG(“while\n”);
DS18X20_find_sensor(&diff, id);
if (diff == OW_ERR_PRESENCE)
{
APP_DEBUG(“All sensors are offline now.\n”);
ow_finit();
return;
}
if (diff == OW_ERR_DATA)
{
APP_DEBUG(“Bus error.\n”);
ow_finit();
return;
}
APP_DEBUG("Bus %d Device %03u Type 0x%02hx (%s) ID %02hx%02hx%02hx%02hx%02hx%02hx CRC 0x%02hx ", UART_PORT, c, id[0], get_type_by_id(id[0]), id[6], id[5], id[4], id[3], id[2], id[1], id[7]);
// fflush(stdout);
c++;if (DS18X20_start_meas(DS18X20_POWER_EXTERN, NULL) == DS18X20_OK) { while (DS18X20_conversion_in_progress() == DS18X20_CONVERTING) { Ql_Sleep(100); /* It will take a while */ } if (DS18X20_read_decicelsius(id, &temp_dc) == DS18X20_OK) { /* Copied from my MCU code, so no float point */ APP_DEBUG("TEMP %3d.%01d C\n", temp_dc / 10, temp_dc > 0 ? temp_dc % 10 : -temp_dc % 10); continue; } } APP_DEBUG("MEASURE FAILED!\n");
}
APP_DEBUG(“Sensors listed.\n”);
}
static void read_temp(void)
{
uint8_t id[] = {40, 39, 86, 153, 11, 0, 0, 151}; // use a known sensor id
int16_t temp_dc;
ow_reset();
if (DS18X20_start_meas(DS18X20_POWER_EXTERN, id) == DS18X20_OK)
{
APP_DEBUG(“start meas\n”);
while (DS18X20_conversion_in_progress() == DS18X20_CONVERTING)
{
APP_DEBUG(“in progress\n”);
Ql_Sleep(50); /* It will take a while */
}
if (DS18X20_read_decicelsius(NULL, &temp_dc) == DS18X20_OK)
{
APP_DEBUG("%2d.%01d C", temp_dc / 10, temp_dc > 0 ? temp_dc % 10 : -temp_dc % 10);
return;
}
}
}
int count = 0;
static void timer_callback(u32 timerId, void *param)
{
APP_DEBUG(“timer called %d\n”, count++);
if (ow_init(Tempreture))
{
APP_DEBUG(“Bus INIT failed. Check COM port.\n”);
return;
}
list_sensors();
//read_temp();
//ow_reset();
ow_finit();
Ql_Timer_Start(TIMER_ID_USER_START + 2, 3000, FALSE);
APP_DEBUG("timer finished\n");
}
when I try to read the sensor all I got is 1 or 0!
any idea?