hi,
I have an LIS3DH accelerometer that is connected to the MC60 module via I2C, and its power supply is 3V.
First, I configured the I2C interface and observed the clock and SDA signals on the oscilloscope.
Then I used the Ql_IIC_Write command to send the command 0x0F , and the accelerometer address is 0x30 .
However, I receive the error -34 , which indicates QL_RET_ERR_I2CHWFAILED , meaning the hardware might have a problem.
I have also read the following forum threads, and I changed the pull-up resistors from 4.7 kΩ to 10 kΩ, but I still got the same “-34” error. Then I changed the supply voltage from 3.0 V to 3.3 V, but I still received the “-34” error. What should I do to fix this error and get the accelerometer to be detected?
1-(mc60-i2c-fails-clock-stretching/6874)
2-(re-mc60-i2c-fails-to-read/53095]
3-(document-sharing-acceleration-sensor-experiment/16164)
“THIS IS MY CODE”
/*****************************************************************************
-
Copyright Statement:
-
-
This software is protected by Copyright and the information contained
-
herein is confidential. The software may not be copied and the information
-
contained herein may not be used or disclosed except with the written
-
permission of Quectel Co., Ltd. 2013
/
/
*
-
Filename:
-
-
main.c
-
Project:
-
-
OpenCPU
-
Description:
-
-
This app demonstrates how to send AT command with RIL API, and transparently
-
transfer the response through MAIN UART. And how to use UART port.
-
Developer can program the application based on this example.
****************************************************************************/
#ifdef CUSTOMER_CODE
#include “ql_trace.h”
#include “ql_system.h”
#include “ql_adc.h”
#include “ql_uart.h”
#include “ql_stdlib.h”
#include “ql_error.h”
#include “ql_spi.h”
#include “ql_iic.h”
#define SDA PINNAME_DCD
#define SCL PINNAME_RI
#define I2C_CHANNEL 0
u8 device_addr = 0x30; //0X19
u8 data = 0x0F;
u8 value = 0;
#define DEBUG_ENABLE 1
#if DEBUG_ENABLE > 0
#define DEBUG_PORT UART_PORT1
#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
static void CallBack_UART_Hdlr(Enum_SerialPort port, Enum_UARTEventType msg, bool level, void* customizedPara)
{
}
/*
DCD PIN->SDA ,PINNAME_DCD
RI PIN->SCL , PINNAME_RI
If input “Ql_IIC_Init=”, that will initialize the IIC channel.
If input “Ql_IIC_Config=”, that will configure the IIC parameters.
If input “Ql_IIC_Write=”, that will write bytes to slave equipment through IIC interface.
If input “Ql_IIC_Read=”, that will read bytes from slave equipment through IIC interface.
If input “Ql_IIC_Write_Read=”, that will read and write bytes through IIC interface.
If input “Ql_IIC_Uninit=”, that will release the IIC pins.
*/
void proc_main_task(s32 taskId)
{
s32 ret;
ST_MSG msg;
// Register & open UART port
ret = Ql_UART_Register(UART_PORT1, CallBack_UART_Hdlr, NULL);
if (ret < QL_RET_OK)
{
Ql_Debug_Trace("Fail to register serial port[%d], ret=%d\r\n", UART_PORT1, ret);
}
ret = Ql_UART_Open(UART_PORT1, 115200, FC_NONE);
if (ret < QL_RET_OK)
{
Ql_Debug_Trace("Fail to open serial port[%d], ret=%d\r\n", UART_PORT1, ret);
}
Ql_IIC_Init(I2C_CHANNEL, SCL, SDA, 1);
Ql_IIC_Config(I2C_CHANNEL, TRUE, device_addr, 100);
Ql_Sleep(500);
APP_DEBUG("I2C Ready...\r\n");
while (TRUE)
{
ret = Ql_IIC_Write(I2C_CHANNEL, device_addr, &data, 1);
APP_DEBUG("Write ret=%d\r\n", ret);
Ql_Sleep(50);
}
}
#endif
THANKS
