go_away

Author Topic: can't work with i2c line following array  (Read 2915 times)

0 Members and 1 Guest are viewing this topic.

Offline PAT_McUserTopic starter

  • Jr. Member
  • **
  • Posts: 32
  • Helpful? 1
  • I just started with robitic.
can't work with i2c line following array
« on: May 14, 2010, 04:07:26 PM »
hi,
I've bought this http://www.roboticsconnection.com/p-67-line-following-sensor.aspx i2c Line Following device.
I want to use it with my axon libs.
I tried to get this function running in sensors.c
Code: [Select]
#define ADDR 0x50
#define BUFFSIZE 0x08
int i2c_LF(void)
{
volatile u08 readbuffer[BUFFSIZE];

int i;

for (i = 0; i < BUFFSIZE; i++)
{
readbuffer[i] = 0;
}

volatile u08 databuffer = 0;
i2cMasterSend(ADDR, 0x01, &databuffer);
i2cMasterReceive(ADDR, BUFFSIZE, readbuffer);

return readbuffer;
}

This is my control.c

Code: [Select]
void control(void){
    //rprintfInit(uart1SendByte); //sets rprintf to USB (for terminal)
//rprintf("\r\nStartup Aplication\n");
configure_ports();
    //Lets start withe the movement and all these things
LED_on();
while(1)
{
i2cInit();
int a=0;
int r=0;
for(a=0;a<1000;a++)
{
rprintf("\r\n Line Following: %d",r);
r=i2c_LF();
delay_ms(100);
}

}
}

I use this this for testing the device only. yes I know that the first print is " Line Following: 0", I want this!
My problem is when i include the "i2c.c" the prog runs to the first prompt " Line Following: 0", if I include the i2c.h the can't be build, errors
sensors.c:75: undefined reference to `i2cMasterSend'
sensors.c:76: undefined reference to `i2cMasterReceive'
control.c:9: undefined reference to `i2cInit'

Please help me,,what can i do?
« Last Edit: May 15, 2010, 03:40:11 PM by PAT_McUser »
I just started with robitic.

PS.: you have to sorry my bad english.

Offline PAT_McUserTopic starter

  • Jr. Member
  • **
  • Posts: 32
  • Helpful? 1
  • I just started with robitic.
Re: can't get i2c to work with line following array
« Reply #1 on: May 15, 2010, 07:37:53 AM »
I've modivied the code of the sensors.c, because the device will answer with a single 8-bit stream. Now its this code in sensors.c:
Code: [Select]
/***************I2C Devices*******************/

//I2C Line Following Sensor Array
#define ADDR 0x50
#define BUFFSIZE 0x01
int i2c_LF(void)
{
volatile u08 readbuffer=0;

volatile u08 databuffer = 0;
i2cMasterSend(ADDR, 0x01, &databuffer);
i2cMasterReceive(ADDR, BUFFSIZE, readbuffer);

return readbuffer;
}
but there is still the problem that the AVR Studio cant build. he throws the following errors:
Quote
sensors.c:68: undefined reference to `i2cMasterSend'
sensors.c:69: undefined reference to `i2cMasterReceive'
Axon_1.o: In function `main':
Axon_1.c:88: undefined reference to `i2cInit'
I just started with robitic.

PS.: you have to sorry my bad english.

Offline PAT_McUserTopic starter

  • Jr. Member
  • **
  • Posts: 32
  • Helpful? 1
  • I just started with robitic.
Re: can't work with i2c line following array
« Reply #2 on: May 15, 2010, 03:39:31 PM »
okay, I managed this on my own.
Problem was I used
Code: [Select]
i2cMasterReceive(ADDR, BUFFSIZE, readbuffer);to receive, but I have to use
Code: [Select]
i2cMasterReceive(ADDR, BUFFSIZE, &readbuffer);But I have still a problem with my prog. after seven times crawling the data the algorithm breaks.
I'll make a new threat, because not really many people likes to read this threat (maybe they are in fear of this ic2-crap).
I think I will write about sex,drugs,rock'n'roll or guns or something like this in the subject. It would be like a magnet for people that visit this forum, maybe I get a answer on my questions with this trick.

Thanks for all listeners and here is the final code:
my control.c
Code: [Select]
/****************************************************************************
*
*   Copyright (c) 2008 [url=http://www.societyofrobots.com]www.societyofrobots.com[/url]
*   (please link back if you use this code!)
*
*   This program is free software; you can redistribute it and/or modify
*   it under the terms of the GNU General Public License version 2 as
*   published by the Free Software Foundation.
*
*   Alternatively, this software may be distributed under the terms of BSD
*   license.
*
****************************************************************************/

//Add your code here
//#include "lcd.c"
#include "pwm.c"
#include "test.c"
#include "beeper.c"

//enter your code in control here
//photovore is just a default sample program and can be deleted
void control(void){
    //rprintfInit(uart1SendByte); //sets rprintf to USB (for terminal)
//rprintf("\r\nStartup Aplication\n");
configure_ports();
    //Lets start withe the movement and all these things
LED_on();
while(1)
{
//test beeper
/*
beper_test();
*/

//test servos
/*
servo_test();
delay_ms(2000);
*/

//test motorcontroll
/*
drive_test();
sabertooth(0,0);
delay_ms(2000);
*/

//test sonar
/*
sonar_test();
*/

//test laser
/*
laser_test();
delay_ms(100);
*/

//test Line Following
LF_test();

}
}
my addition to sensors.c
Code: [Select]
/***************I2C Devices*******************/

//I2C Line Following Sensor Array
#define ADDR 0x50
#define BUFFSIZE 0x01
int i2c_LF(void)
{
volatile u08 readbuffer=0x00;
volatile u08 databuffer = 0;
i2cMasterSend(ADDR, 0x01, &databuffer);
i2cMasterReceive(ADDR, BUFFSIZE, &readbuffer);
return readbuffer;
}
my Axon.c (the myterious main ;-) )
Code: [Select]
/****************************************************************************
*
*   Copyright (c) 2008 [url=http://www.societyofrobots.com]www.societyofrobots.com[/url]
*   (please link back if you use this code!)
*
*   This program is free software; you can redistribute it and/or modify
*   it under the terms of the GNU General Public License version 2 as
*   published by the Free Software Foundation.
*
*   Alternatively, this software may be distributed under the terms of BSD
*   license.
*
****************************************************************************/

//SoR Include
#include "SoR_Utils.h" //includes all the technical stuff
#include "hardware.c" //declare hardware variables and ports
//#include "CMUcam.c" //not yet written
#include "sensors.c" //sensor libraries for sonar, sharp IR, etc.
#include "misc.c" //includes libraries for various hardware and other useful stuff
#include "axon_DAQ.c" //use the Axon like a data acquisition device
//#include "Blackfin_Axon.c" //files for Blackfin Robot camera
#include "control.c" //your code goes in here
//#include "servo_controller.c" //Axon servo controller
//#include "test.c" //include this is doing a function test for the Axon
//#include "axon_oscope_test.c" //include this is doing a function test for the Axon
#include <string.h>
#include "laser.c"
#include "i2c.h"
#include "i2c.c"



int main(void)
{
//declare variables here
int i=0;//useless variable
int j=0;//useless variable

//add 1.7s delay for potential power issues
delay_cycles(65535);
delay_cycles(65535);
delay_cycles(65535);
delay_cycles(65535);
delay_cycles(65535);
delay_cycles(65535);
delay_cycles(65535);

/****************INITIALIZATIONS*******************/
//other stuff Im experimenting with for SoR
uartInit();  // initialize the UART (serial port)
    uartSetBaudRate(0, 38400); // set UARTE speed, for Bluetooth
uartSetBaudRate(1, 115200); // set UARTD speed, for USB connection, up to 500k, try 115200 if it doesn't work
    //uartSetBaudRate(2, 19200);
uartSetBaudRate(2, 38400);
    uartSetBaudRate(3, 38400); // set UARTJ speed, for Blackfin
//G=Ground, T=Tx (connect to external Rx), R=Rx (connect to external Tx)

rprintfInit(uart1SendByte);// initialize rprintf system and configure uart1 (USB) for rprintf
//rprintfInit(uart2SendByte);//Sets UART2 as chosen in rprintf system

configure_ports(); // configure which ports are analog, digital, etc.

LED_on();

rprintf("\r\nSystem Warmed Up");

// initialize the timer system
  init_timer0(TIMER_CLK_1024);
  init_timer1(TIMER_CLK_64);
  init_timer2(TIMER2_CLK_64);
  init_timer3(TIMER_CLK_64);
  init_timer4(TIMER_CLK_64);
  init_timer5(TIMER_CLK_64);

a2dInit(); // initialize analog to digital converter (ADC)
a2dSetPrescaler(ADC_PRESCALE_DIV32); // configure ADC scaling
a2dSetReference(ADC_REFERENCE_AVCC); // configure ADC reference voltage

//let system stabelize for X time
for(i=0;i<16;i++)
{
j=a2dConvert8bit(i);//read each ADC once to get it working accurately
delay_cycles(5000); //keep LED on long enough to see Axon reseting
rprintf(".");
}

LED_off();
LASER_off();
i2cInit();
//i2cSetBitrate(100);
//i2cSetLocalDeviceAddr(0x42,TRUE);


rprintf("Initialization Complete \r\n");

/**************************************************/

//test programs
//while(1)
//{
//test_oscope();
//test();
//while(!button_pressed());

//PWM_Init_timer3_E3(8);
//PWM_timer3_On_E3();
//PWM_timer3_Set_E3(30);
//axon_DAQ();//activate the slow DAQ software (data acquisition), all 16 sensors, ~10ms resolution
//axon_DAQ_fast();//activate the super fast DAQ, only ADC pin 9, ~1ms resolution
//}

/*********ADD YOUR CODE BELOW THIS LINE **********/

//wait until user pushes button
rprintf("Waiting for Input \r\n");
while(!button_pressed());

//reset all timers to zero
reset_timer0();
reset_timer1();
reset_timer2();
reset_timer3();
reset_timer4();
reset_timer5();

while(1)
{
control();//uncomment this for your code (and use control.c only to program)

//servo_controller();

//below is various test code for Admin
/*
PWM_Init_timer1_LED(8);
PWM_timer1_On_LED();
while(1)
{
for(i=90;i<255;i++)
{
PWM_timer1_Set_LED(i);
delay_ms(10);
}
for(i=255;i>90;i--)
{
PWM_timer1_Set_LED(i);
delay_ms(10);
}
rprintf("stuff\r\n");
}

rprintf("Initializing timer2 for PWM\r\n");
PWM_Init_timer1_LED(8);
PWM_Init_timer2_H6(8);//9 doesn't work
PWM_Init_timer3_E3(8);
PWM_Init_timer3_E4(8);
PWM_Init_timer3_E5(8);
delay_ms(100);
rprintf("2");
//PWM_Init_timer4_H3(10);
delay_ms(100);
rprintf("3");
//PWM_Init_timer4_H4(10);
delay_ms(100);
rprintf("4");
//PWM_Init_timer4_H5(10);
delay_ms(100);
rprintf("5");

rprintf("Turning on both PWM channels\r\n");
PWM_timer1_On_LED();
PWM_timer2_On_H6();
PWM_timer3_On_E3();
PWM_timer3_On_E4();
PWM_timer3_On_E5();
PWM_timer4_On_H3();
PWM_timer4_On_H4();
PWM_timer4_On_H5();
delay_ms(1000);

rprintf("Setting PWM to 1%% duty cycle\r\n");
PWM_timer1_Set_LED(1);
PWM_timer2_Set_H6(1);
PWM_timer3_Set_E3(1);
PWM_timer3_Set_E4(1);
PWM_timer3_Set_E5(1);
PWM_timer4_Set_H3(1);
PWM_timer4_Set_H4(1);
PWM_timer4_Set_H5(1);
delay_ms(1000);

rprintf("Setting PWM to 50%% duty cycle\r\n");
PWM_timer1_Set_LED(127);
PWM_timer2_Set_H6(127);
PWM_timer3_Set_E3(127);
PWM_timer3_Set_E4(127);
PWM_timer3_Set_E5(127);
PWM_timer4_Set_H3(127);
PWM_timer4_Set_H4(127);
PWM_timer4_Set_H5(127);
delay_ms(1000);

rprintf("Setting PWM to 99%% duty cycle\r\n");
PWM_timer1_Set_LED(254);
PWM_timer2_Set_H6(254);
PWM_timer3_Set_E3(254);
PWM_timer3_Set_E4(254);
PWM_timer3_Set_E5(254);
PWM_timer4_Set_H3(254);
PWM_timer4_Set_H4(254);
PWM_timer4_Set_H5(254);
delay_ms(1000);

rprintf("Turning off PWM\r\n");
PWM_timer1_Off_LED();
PWM_timer2_Off_H6();
PWM_timer3_Off_E3();
PWM_timer3_Off_E4();
PWM_timer3_Off_E5();
PWM_timer4_Off_H3();
PWM_timer4_Off_H4();
PWM_timer4_Off_H5();
delay_ms(1000);
*/
delay_cycles(100);//an optional small delay to prevent crazy oscillations
}
/*********ADD YOUR CODE ABOVE THIS LINE **********/

return 0;
}
I just started with robitic.

PS.: you have to sorry my bad english.

Offline PAT_McUserTopic starter

  • Jr. Member
  • **
  • Posts: 32
  • Helpful? 1
  • I just started with robitic.
Re: can't work with i2c line following array
« Reply #3 on: May 18, 2010, 06:19:49 AM »
Here is the new version of the sensors.c-add, now you can capture data till you die ;-)

Code: [Select]
#define ADDR 0x50
#define BUFFSIZE 0x01
u08 i2c_LF(void)
{
i2cInit();
volatile u08 readbuffer=0x00;
volatile u08 databuffer = 0;
i2cMasterSend(ADDR, 0x01, databuffer);
i2cMasterReceiveNI(ADDR, BUFFSIZE, &readbuffer);
return readbuffer;

}

(i2c.c and i2c.h are standard taken from AVR)
I just started with robitic.

PS.: you have to sorry my bad english.

 


Get Your Ad Here

data_list