|
|
View previous topic :: View next topic |
Author |
Message |
soko
Joined: 05 Jun 2011 Posts: 9
|
Help with I2C - 16F88 and WII Motion Plus (Accelerometers) |
Posted: Sun Jun 05, 2011 12:07 pm |
|
|
Hello!
I'm trying to read an I2C device, exactly one of the Wii Nunchuk, to get data from your accelerometers, but no way to compile the following code.
Code: | #include <16f88.h> //pic a utilizar
#fuses NOWDT,NOPROTECT,PUT,NOLVP, NOMCLR,INTRC_IO //ordenes para el programador
#use delay (clock=8000000) //Fosc=8Mhz
#define use_portb_lcd TRUE //definir portb lcd
#include<LCD.c> //libreria manejo lcd
#use I2C (SLAVE,SDA=PIN_A1,SCL=PIN_A0,ADDRESS=0X52,SLOW,FORCE_HW)
void main(void){ // FUNCION PRINCIPAL
setup_oscillator(OSC_8MHZ|OSC_INTRC); // Activa el oscilador interno.
set_tris_b(0x00); //Puerto B como SALIDA.
delay_ms(100);
lcd_init();
long dato;
while(true){
if(i2c_poll()) {
dato=i2c_read();
lcd_gotoxy(1,1);
printf(lcd_putc,"Valor:");
lcd_gotoxy(1,2);
printf(lcd_putc,"%03lu",dato);
delay_ms(300);
}
}
} |
This is the error:
Quote: | Executing: "C:\Archivos de programa\PICC\Ccsc.exe" +FM "WOOKO_V5.c" #__DEBUG=1 +ICD +DF +LN +T +A +M +Z +Y=9 +EA #__16F88=TRUE
*** Error 12 "WOOKO_V5.c" Line 14(17,18): Undefined identifier -- i2c_poll
1 Errors, 0 Warnings.
Halting build on first failure as requested.
BUILD FAILED: Sun Jun 05 19:52:09 2011 |
you can help me with this problem?, thanks
Last edited by soko on Tue Jun 07, 2011 7:30 am; edited 1 time in total |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Sun Jun 05, 2011 12:18 pm |
|
|
the function 'i2c_poll()' is not recognized by the compiler. Perhaps it is a function contained within a 'header' or 'devices' file similar to the #include lcd.c that you added for the LCd functions ?
or if
it is a valid compiler function, perhaps you've mistyped it or it needs additional information.
If you press F11 while in MPLAB, the CCS HELP pages will appear, consult them or the manual for further information !! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jun 05, 2011 2:10 pm |
|
|
Read the manual:
Quote: | i2c_poll( )
Syntax:
i2c_poll()
i2c_poll(stream)
Parameters: stream (optional)- specify the stream defined in #USE I2C
Returns:
1 (TRUE) or 0 (FALSE)
Function: The I2C_POLL() function should only be used when the built-in SSP is used. |
Pins A0 and A1 are not the hardware SSP pins:
Quote: | #include <16f88.h> //pic a utilizar
#fuses NOWDT,NOPROTECT,PUT,NOLVP, NOMCLR,INTRC_IO //ordenes para el programador
#use delay (clock=8000000) //Fosc=8Mhz
#define use_portb_lcd TRUE //definir portb lcd
#include<LCD.c> //libreria manejo lcd
#use I2C (SLAVE,SDA=PIN_A1,SCL=PIN_A0,ADDRESS=0X52,SLOW,FORCE_HW)
|
The hardware i2c pins on the 16F88 are Pin B1 for SDA, and Pin B4 for SCL. |
|
|
soko
Joined: 05 Jun 2011 Posts: 9
|
|
Posted: Sun Jun 05, 2011 4:12 pm |
|
|
Thank you very much.
I'll try the settings and then I tell you. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jun 05, 2011 4:56 pm |
|
|
Quote: | #define use_portb_lcd TRUE |
Also I noticed that you're using the CCS LCD driver on Port B. If you use
the hardware i2c pins, you can't use all of Port B for the LCD. You can
use other pins for the LCD if you use a modern CCS lcd driver, or if
you use the Flex driver. For example, you could use some pins on Port A
and some pins on Port B (other than B1 and B4) for the LCD:
http://www.ccsinfo.com/forum/viewtopic.php?t=24661 |
|
|
soko
Joined: 05 Jun 2011 Posts: 9
|
|
Posted: Tue Jun 07, 2011 7:28 am |
|
|
hello again!
Thanks to your help, I have working examples with i2c, but the program still works fine.
According to specifications of this website:
http://wiibrew.org/wiki/Wiimote/Extension_Controllers#Wii_Motion_Plus
I programed this code, but it hangs at the instruction:
Code: | i2c_start();
i2c_write(0xA5); // leo valores WMP |
Some friendly advice?
Thanks and sorry for my English because I'm not native.
Code: | #include <16F88.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES PUT //No Power Up Timer
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOCPD //No EE protection
#FUSES BROWNOUT //No brownout reset
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOWRT //Program memory not write protected
#FUSES RESERVED //Used to set the reserved FUSE bits
#use delay(clock=8000000)
#use i2c(Master,sda=PIN_B1,scl=PIN_B4,fast)
#include <LCD_PORT_A.c> //libreria manejo lcd
int t,i;
int datos[6] = {0}; // Valor en exadecimal
int16 yaw=0,pitch=0,roll=0; // Lecturas WMP
void inicio_wm() {
i2c_start();
i2c_write(0xA6);
i2c_write(0xF0);
i2c_write(0x55);
i2c_stop();
delay_ms(1);
i2c_write(0xA6);
i2c_write(0xFE);
i2c_write(0x05);
i2c_stop();
}
void LCD(){
lcd_gotoxy(1,1);
printf(lcd_putc,"Yaw- Roll -Pitch");
lcd_gotoxy(1,2);
printf(lcd_putc,"%02u%02u-%02u%02u-%02u%02u",datos[0],datos[1],datos[2],datos[3],datos[4],datos[5]);
delay_ms(30);
}
void main() {
lcd_init();
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_2);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
inicio_wm();
delay_ms(10);
while(1) {
i2c_start(); //Preparamos WMP para pedir datos
i2c_write(0xA4);
i2c_write(0x00); //Se manda 0 antes de cada peticiĆ³n de datos
delay_ms(1);
i2c_start();
i2c_write(0xA5); // leo valores WMP
for (t=0;t<5;t++)
datos[t] = i2c_read();
datos[5] = i2c_read(0);
i2c_stop();
LCD();
}
} |
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Tue Jun 07, 2011 8:41 am |
|
|
well my Spanish isn't good to read the comments !
... but...
do you have the proper value pullups on the I2C lines ? |
|
|
soko
Joined: 05 Jun 2011 Posts: 9
|
|
Posted: Tue Jun 07, 2011 8:59 am |
|
|
Ok, sorry.
Here is the translated code, I hope to be better.
The pull-up resistors are integrated in the device itself, have a value of 2k2.
Thanks for the advice.
Code: | int t;
int datos[6] = {0}; // DATA READ
void inicio_wm() { // WII MOTION PLUS DATA CONTROL
i2c_start();
i2c_write(0xA6);
i2c_write(0xF0);
i2c_write(0x55);
i2c_stop();
delay_ms(1);
i2c_write(0xA6);
i2c_write(0xFE);
i2c_write(0x05);
i2c_stop();
}
void LCD(){
lcd_gotoxy(1,1);
printf(lcd_putc,"Yaw- Roll -Pitch");
lcd_gotoxy(1,2);
printf(lcd_putc,"%02u%02u-%02u%02u-%02u%02u",datos[0],datos[1],datos[2],datos[3],datos[4],datos[5]);
delay_ms(30);
}
void main() {
lcd_init();
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_2);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
inicio_wm();
delay_ms(10);
while(1) {
i2c_start(); //INICIALIZE WII MP
i2c_write(0xA4); // DIRECCION OF WMP
i2c_write(0x00); //SEND 0
delay_ms(1);
i2c_start();
i2c_write(0xA5); //READ WMP OUT VALUES
for (t=0;t<5;t++) // BUFFER VALUES IN A VECTOR OF 6 DATAS
datos[t] = i2c_read();
datos[5] = i2c_read(0);
i2c_stop(); // STOP I2C
LCD(); // PRINT DATAS
}
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jun 07, 2011 12:31 pm |
|
|
Run this program. It will list all devices on the i2c bus that it can find.
See if it detects your Nunchuck. What does it show ?
http://www.ccsinfo.com/forum/viewtopic.php?t=42368&start=4
Modify top few lines of the program (#include statement, etc.) to fit
your 16F88 setup. |
|
|
soko
Joined: 05 Jun 2011 Posts: 9
|
|
Posted: Tue Jun 07, 2011 2:03 pm |
|
|
It works!!!
Thank you very much everyone !!!!! At the end with your advice and get directions program has worked.
Also find information on this website, where you can see the code that works.
http://www.todopic.com.ar/foros/index.php?topic=30669.0
Greetings and thanks. |
|
|
gogutier
Joined: 12 Jul 2011 Posts: 4
|
|
Posted: Mon Apr 30, 2012 11:09 pm |
|
|
very useful, thanks! |
|
|
|
|
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
|