|
|
View previous topic :: View next topic |
Author |
Message |
Saelee
Joined: 16 Oct 2016 Posts: 4
|
Problem with error "Improper use of a function identifi |
Posted: Tue Oct 18, 2016 3:56 am |
|
|
Hello everybody
I'm newbie for CCS compiler
I try to connect my mpu6050 with pic16f887 and send data to pc by serial port, but I can't compile this code because error "Improper use of a function identifier" in line 12 " while(TRUE) "
please help me solve it
Code: | #include <16F887.h>
#use delay(clock=4000000)
#use I2C(master,sda=PIN_C4,scl=PIN_C3,slow,restart_wdt)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)
#include "mpu6050.c"
void main()
{
signed int8 A_data[6];
signed int16 Xa=0,Ya=0,Za=0;
while(TRUE)
{
A_data[0]=mpu6050_read(0x3B); //Read X axis(LSB)
A_data[1]=mpu6050_read(0x3C); //Read X axis(MSB)
A_data[2]=mpu6050_read(0x3D); //Read Y axis(LSB)
A_data[3]=mpu6050_read(0x3E); //Read Y axis(MSB)
A_data[4]=mpu6050_read(0x3F); //Read Z axis(LSB)
A_data[5]=mpu6050_read(0x40); //Read Z axis(MSB)
Xa=make16(A_data[0],A_data[1]);
Ya=make16(A_data[2],A_data[3]);
Za=make16(A_data[4],A_data[5]);
printf("X:%ld ",Xa);
printf("Y:%ld ",Ya);
printf("Z:%ld ",Za);
delay_ms(100);
}
}
|
I modify code from >> http://www.sonsivri.to/forum/index.php?topic=59978.0 |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9247 Location: Greensville,Ontario
|
|
Posted: Tue Oct 18, 2016 4:54 am |
|
|
You need to show us this driver code..
#include "mpu6050.c"
as line 12 might be the first access of it.
now general comments
1) Always add 'errors' to the use rs232(...options...) otherwise UART buffer will 'stall' or 'hang' after 2-3 incoming characters...
2) Always compile and run PCM P's 'I2C scanner' program that's in the code library when using I2C devices. It WILL tell you if the PIC can 'see' the I2C device ! This will confirm the hardware is correct !!
3) Most (all) devices require a 'setup' or 'initialization'. At this time, registers will be configured, perhaps a delay for sync, etc. I don't see that in your program, so perhaps the device isn't properly configured?
4) CPU clock is only 4MHz. You should go faster 8,16, ?? so that you can do more in less time., though 4 Megs is a good 'test bench' speed as instructions take 1us each (jumps 2).
Jay |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1937 Location: Norman, OK
|
|
Posted: Tue Oct 18, 2016 5:10 am |
|
|
If you copied the exact code shown at the link, the MPU6050 library is not
complete. For one thing it is missing the closing brace at the end. I don't
know what other modifications you have made. _________________ Google and Forum Search are some of your best tools!!!! |
|
|
Saelee
Joined: 16 Oct 2016 Posts: 4
|
|
Posted: Tue Oct 18, 2016 5:10 am |
|
|
this driver code, I copy from >>http://www.sonsivri.to/forum/index.php?topic=59978.0
Code: | // MPU6050 required Registers
#define W_DATA 0xD0
#define R_DATA 0xD1
#define PWR_MGMT_1 0x6B
#define PWR_MGMT_2 0x6C
#define SMPRT_DIV 0x19
#define CONFIG_R 0x1A
#define GYRO_CONFIG 0x1B
#define ACCEL_CONFIG 0x1C
#define ACCEL_XOUT_H 0x3B
#define ACCEL_XOUT_L 0x3C
#define ACCEL_YOUT_H 0x3D
#define ACCEL_YOUT_L 0x3E
#define ACCEL_ZOUT_H 0x3F
#define ACCEL_ZOUT_L 0x40
#define TEMP_OUT_H 0x41
#define TEMP_OUT_L 0x42
#define GYRO_XOUT_H 0x43
#define GYRO_XOUT_L 0x44
#define GYRO_YOUT_H 0x45
#define GYRO_YOUT_L 0x46
#define GYRO_ZOUT_H 0x47
#define GYRO_ZOUT_L 0x48
void mpu6050_write(int add, int data)
{
i2c_start();
i2c_write(W_DATA);
i2c_write(add);
i2c_write(data);
i2c_stop();
}
int16 mpu6050_read(int add){
int retval;
i2c_start();
i2c_write(W_DATA);
i2c_write(add);
i2c_start();
i2c_write(R_DATA);
retval=i2c_read(0);
i2c_stop();
return retval;
}
void mpu6050_init(){
mpu6050_write(PWR_MGMT_1, 0x80);
delay_ms(100);
mpu6050_write(PWR_MGMT_1, 0x00);
delay_ms(100);
mpu6050_write(CONFIG_R, 0x01);
delay_ms(10);
mpu6050_write(GYRO_CONFIG, 0x00);
|
|
|
|
Saelee
Joined: 16 Oct 2016 Posts: 4
|
|
Posted: Tue Oct 18, 2016 5:21 am |
|
|
Hi jay and dyeatman
now I can compile it !!!!
thank you very much sir. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|