Tool/software: TI-RTOS
Hi,
I am using TM4C123GH6PM controller with TI-RTOS for Tiva C v: 2.16.00.08. I need to communicate with Pixy Cam5 which support I2C as slave (Addr :0x54).
I went through I2C example from the TI-RTOS sdk which downloaded through CCS.
Whenever I run the code it is going to IDLE mode. I checked with break points and used step in button to execute each step. In taskFxn fucntion it should execute inside while loop but before that it is going to IDLE mode.
I am not getting which I2C is enabled. So I iteratively connected to 0-3 I2C ports, none worked well.
I have attached my main function and extra header file that I have created for Camera.
/*
* Copyright (c) 2015, Texas Instruments Incorporated
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* ======== i2ctmp006.c ========
*/
/* XDCtools Header files */
#include <xdc/std.h>
#include <xdc/runtime/System.h>
/* BIOS Header files */
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
/* TI-RTOS Header files */
#include <ti/drivers/GPIO.h>
#include <ti/drivers/I2C.h>
/* Example/Board Header files */
#include "Board.h"
#include "pixy_header.h"
#define TASKSTACKSIZE 640
Task_Struct task0Struct;
char task0Stack[TASKSTACKSIZE];
/*
int count = 0;
void gpioButtonFxn0(unsigned int index)
{
Clear the GPIO interrupt and toggle an LED
GPIO_toggle(Board_LED0);
if (count++ == 100) {
count = 0;
}
}
*/
uint8_t getByte()
{
uint8_t txBuffer[1];
uint8_t rxBuffer[1];
I2C_Handle i2c;
I2C_Params i2cParams;
I2C_Transaction i2cTransaction;
/* Create I2C for usage */
I2C_Params_init(&i2cParams);
i2cParams.bitRate = I2C_400kHz;
i2c = I2C_open(Board_I2C_TMP, &i2cParams);
txBuffer[0] = 0x00;
i2cTransaction.slaveAddress = Board_PIXY_ADDR;
i2cTransaction.writeBuf = txBuffer;
i2cTransaction.writeCount = 0;
i2cTransaction.readBuf = rxBuffer;
i2cTransaction.readCount = 1;
I2C_transfer(i2c, &i2cTransaction);
/* Deinitialized I2C */
I2C_close(i2c);
return rxBuffer[0];
}
/*
* ======== taskFxn ========
* Task for this function is created statically. See the project's .cfg file.
*/
void taskFxn(UArg arg0, UArg arg1)
{
int i;
uint8_t prev = 0;
int maxblock = 100;
/* Turn on user LED */
GPIO_write(Board_LED1, Board_LED_ON); //Green
for(i=1000;i>0;i--);
GPIO_write(Board_LED1, Board_LED_OFF);
for(i=1000;i>0;i--);
while(1)
{
getStart();
int ret = getBlocks(maxblock);
for(i=0;i<ret;i++)
{
int color = g_blocks[i].signature;
if ( prev != color )
{
switch(color)
{
case 1 : //printf("Green\n");
GPIO_write(Board_LED1, Board_LED_ON); //Green LED
break;
case 2 : // printf("Orange\n");
GPIO_write(Board_LED2, Board_LED_ON); //Red LED
break;
case 3 : //printf("Yellow\n");
GPIO_write(Board_LED0, Board_LED_ON); //Blue LED
break;
}
}
prev = color;
//Task_sleep(100);
}
}
}
void taskFxn_1(UArg arg0, UArg arg1)
{
int i;
while(1){
GPIO_write(Board_LED1, Board_LED_ON); //Green
for(i=1000000;i>0;i--);
GPIO_write(Board_LED1, Board_LED_OFF);
for(i=1000000;i>0;i--);
}
}
/*
* ======== main ========
*/
int main(void)
{
// int i;
Task_Params taskParams;
System_printf("Inside I2C Example\n");
/* Call board init functions */
Board_initGeneral();
Board_initGPIO();
Board_initI2C();
init();
/* Construct tmp006 Task thread */
Task_Params_init(&taskParams);
taskParams.stackSize = TASKSTACKSIZE;
taskParams.stack = &task0Stack;
Task_construct(&task0Struct, (Task_FuncPtr)taskFxn, &taskParams, NULL);
// GPIO_write(Board_LED0, Board_LED_ON); //blue
System_printf("Starting the I2C example\nSystem provider is set to SysMin."
" Halt the target to view any SysMin contents in ROV.\n");
/* SysMin will only print to the console when you call flush or exit */
System_flush();
#if 0
/* install Button callback */
GPIO_setCallback(Board_BUTTON0, gpioButtonFxn0);
/* Enable interrupts */
GPIO_enableInt(Board_BUTTON0);
#endif
/* Start BIOS */
BIOS_start();
return (0);
}
About Camera:-
Pixy cam can identify up to 7 colors, that we can configure from PixyMon application. So using their API we can get which color is identified. When using I2C we do not have to read from particular register, On sending read command Pixy will write which all colors identified.
www.cmucam.org/.../Porting_Guide
Can you help me to solve this problem.