- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hi,
first, I want say sorry to you for my english.
I'm using cy8ckit-044 as master to read out the data from mpu9250 via i2c communication.
I got error "implicit declaration of function 'I2C_MPU9250_I2CMasterSendStart' is invalid in c99".
I have looked at default file of i2c and get this for MasterSendStart function
"uint32 I2C_MPU9250_I2CMasterSendStart(uint32 slaveAddress, uint32 bitRnW, uint32 timeoutMs);"
another thing I confused is in another examples for i2c the MasterSendStart function is
"uint8 I2C_MPU9250_Master_MasterSendStart(uint8 slaveAddress, uint8 R_nW)"
there isn't uint32 timeoutMs, why is this happen?
I have tried to write the timeoutMs with "100u" and even make variable #define I2C_TimeOut (100u) in file.h (shown below) but it still error.
I2C_MPU9250_I2CMasterSendStart(address,MPU9250_WRITE, 100u);
or
I2C_MPU9250_I2CMasterSendStart(address,MPU9250_WRITE,I2C_TimeOut); //#define I2C_TimeOut (100u) in file.h
anyone have solution?
thank,
Dwi.
Solved! Go to Solution.
- Labels:
-
ispn:39614:1:0
-
l1:314:1:0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Dwi-san,
(1) Please include "project.h" in mpu9250.c and i2c.c
NOTE: BTW the name "i2c.c" and "i2c.h" are very prone to conflict with system library source names,
I would suggest to pick some other name to be safe.
(2) Add "I2C_TimeOut" in the argument of many I2C_MPU9250_I2CMasterXXXX()
(3) Note I2C_MPU9250_I2CMasterReadByte() does not return read data, data must be in the argument list.
(4) There was ONE "I2C_MPU9250_I2CMasterSendStop() ;" which throws too few arguments error
even when I added "I2C_TimeOut" in the argument list,
so I copied another call of this function from non error part of the source
and replaced the line with it. Then the error was gone.
I think that there must have been some non printable letter of non standard US ascii letter included in the line.
(5) Now the first error is in the beginning of interrupt.h which I hope that you are the one to fix...
Best Regards,
12-Feb-2020
Motoo Tanaka
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Dwi-san,
I think that
"uint8 I2C_MPU9250_Master_MasterSendStart(uint8 slaveAddress, uint8 R_nW)"
is an older version of
"uint32 I2C_MPU9250_I2CMasterSendStart(uint32 slaveAddress, uint32 bitRnW, uint32 timeoutMs);"
as sometimes I2C bus fails to respond and without timeout it hangs the total system.
And the error(s) you are getting seems to be there is/are typo in your project
or there is/are mixed versions of I2C APIs.
Or sometime we can clear the problem just clean and re-build the project.
Anyway without your sample project which can reproduce the problem attached, it's very difficult to verify.
FYI, the following is a simple I2C test program I wrote this morning utilizing my old sample and library.
Being a lazy, I wrote my wrapper functions for I2C, such as
==================
uint32 i2c_SendRestart(uint32 bitRnW)
{
return(I2C_I2CMasterSendRestart(i2c_slave_address, bitRnW, TIMEOUT_MSEC));
}
==================
schematic
pins
Tera Term log
Note: I used a LM75B (address 0x48) for testing, you can change the line
i2c_set_slave_address(LM75B_I2C_SLAVE_ADDR) ;
to use your device's address to test.
i2c_utils.c (My I2C wrapper functions)
==================
#include <project.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include "i2c_utils.h"
#define TIMEOUT_MSEC 300u
uint8 i2c_slave_address = 0x00 ;
uint32 i2c_status(void)
{
return(I2C_I2CMasterStatus());
}
uint32 i2c_ClearStatus(void)
{
return(I2C_I2CMasterClearStatus());
}
void i2c_set_slave_address(uint8 newAddress)
{
i2c_slave_address = newAddress ;
}
uint8 i2c_get_slave_address(void)
{
return( i2c_slave_address );
}
uint32 i2c_SendStart(uint8 rw)
{
return(I2C_I2CMasterSendStart(i2c_slave_address, (uint32)rw, TIMEOUT_MSEC));
}
uint32 i2c_SendRestart(uint32 bitRnW)
{
return(I2C_I2CMasterSendRestart(i2c_slave_address, bitRnW, TIMEOUT_MSEC));
}
uint32 i2c_SendStop(void)
{
return(I2C_I2CMasterSendStop(TIMEOUT_MSEC));
}
uint8 i2c_readByte(uint32_t acknak) /* 6-Mar-2018 acknak added */
{
uint8 data ;
(void)I2C_I2CMasterReadByte(acknak, &data, TIMEOUT_MSEC) ; /* ignore error */
return( data ) ;
}
uint8 i2c_readReg(uint8 addr)
{
uint8 data ;
i2c_SendStart(0u) ; /* for write */
i2c_writeByte(addr) ; /* who am i */
i2c_SendRestart(0x1u) ; /* for read */
CyDelay(1) ;
data = i2c_readByte(I2C_I2C_NAK_DATA) ;
i2c_SendStop() ;
return( data ) ;
}
void i2c_readRegs(uint8 addr, uint8 *data, int len)
{
int i ;
i2c_SendStart(0u) ; /* for write */
i2c_writeByte(addr) ;
i2c_SendRestart(0x1u) ; /* for read */
for (i = 0 ; i < len-1 ; i++ ) {
CyDelay(1) ;
data = i2c_readByte(I2C_I2C_ACK_DATA) ;
}
data = i2c_readByte(I2C_I2C_NAK_DATA) ;
i2c_SendStop() ;
}
uint32 i2c_writeByte(uint8 data)
{
uint32 theByte, result ;
// I2C_I2CMasterSendStart((uint32)i2c_slave_address, 0u);
theByte = data ;
result = I2C_I2CMasterWriteByte(theByte, TIMEOUT_MSEC) ;
// I2C_I2CMasterSendStop() ;
return(result) ;
}
void i2c_writeReg(uint8 addr, uint8 data)
{
i2c_SendStart(0u) ; /* for write */
i2c_writeByte(addr) ; /* write register address */
CyDelay(1) ;
i2c_writeByte(data) ;
i2c_SendStop() ;
}
void i2c_writeRegs(uint8 addr, uint8 *data, int len)
{
int i ;
i2c_SendStart(0u) ; /* for write */
i2c_writeByte(addr) ;
i2c_SendRestart(0x0u) ; /* for write */
CyDelay(1) ;
for (i = 0 ; i < len ; i++ ) {
i2c_writeByte(data) ;
}
i2c_SendStop() ;
}
==================
main.c
==================
#include "project.h"
#include <stdio.h>
#include "i2c_utils.h"
#define LM75B_I2C_SLAVE_ADDR (0x48)
#define STR_LEN 128
char str[STR_LEN+1] ; /* print buffer */
void print(char *str)
{
UART_UartPutString(str) ;
}
void cls(void)
{
print("\033c") ; /* reset */
CyDelay(20) ;
print("\033[2J") ; /* clear screen */
CyDelay(20) ;
}
void splash(void)
{
cls() ;
snprintf(str, STR_LEN, "PSoC 4 I2C (LM75B) Test (%s %s)\n", __DATE__, __TIME__) ;
print(str) ;
}
void init_hardware(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
UART_Start() ;
splash() ;
I2C_Start() ;
i2c_set_slave_address(LM75B_I2C_SLAVE_ADDR) ;
}
int main(void)
{
uint8_t reg_addr = 0 ;
int8_t data ;
init_hardware() ;
for(;;)
{
data = i2c_readReg(reg_addr) ;
snprintf(str, STR_LEN, "%d\n", data) ;
print(str) ;
CyDelay(1000) ; /* 1sec */
}
}
==================
Best Regards,
12-Feb-2020
Motoo Tanaka
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Tanaka-san,
thank for your answer, it's help me for some issues. But, my project is still has same errors.
I have tried to check if there're typo in my project and I didn't see the typo.
then, for mixed versions of I2C APIs I don't know how to check it.
I attach my project, hope it will help.
Regards,
Dwi Wahyudi.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Dwi-san,
(1) Please include "project.h" in mpu9250.c and i2c.c
NOTE: BTW the name "i2c.c" and "i2c.h" are very prone to conflict with system library source names,
I would suggest to pick some other name to be safe.
(2) Add "I2C_TimeOut" in the argument of many I2C_MPU9250_I2CMasterXXXX()
(3) Note I2C_MPU9250_I2CMasterReadByte() does not return read data, data must be in the argument list.
(4) There was ONE "I2C_MPU9250_I2CMasterSendStop() ;" which throws too few arguments error
even when I added "I2C_TimeOut" in the argument list,
so I copied another call of this function from non error part of the source
and replaced the line with it. Then the error was gone.
I think that there must have been some non printable letter of non standard US ascii letter included in the line.
(5) Now the first error is in the beginning of interrupt.h which I hope that you are the one to fix...
Best Regards,
12-Feb-2020
Motoo Tanaka