Other Parts Discussed in Thread: TMS570LS1224, HALCOGEN
I am trying to I2C communicate a launchpad TMS570LS12x as a master and an arduino as a slave. I am using the sample code above, they are just example. I am using pin 9 and 10 of J6 of the launchpad for I2C communication and A4 and A5 on arduino fot SDA and SCL. They do not communicate, Seems to be a launchpad programming problem because due to the two pull up resistors, I always see 3.3V in bouth lines with the oscilloscope. Moreover, using the CCS debbugging, I go into an infinite loop when I try to send data from Launchpad to Arduino. I would like to ask if I should select wich I2C port I have to use in the launchpad as there are 2 I2c port, and how I do it. I think I should not define registers as I am using halchogen library, but should I define some register for I2C? What could be the problem on having always high signal on I2C line and going in an infinite loop?
Arduino:
// Wire Slave Receiver
// by Nicholas Zambetti <<a href="www.zambetti.com>">http:/.../a>
// Demonstrates use of the Wire library
// Receives data as an I2C/TWI slave device
// Refer to the "Wire Master Writer" example for use with this
// Created 29 March 2006
// This example code is in the public domain.
#include <Wire.h>
void setup()
{
Wire.begin(4); // join i2c bus with address #4
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600); // start serial for output
}
void loop()
{
delay(100);
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
while(1 < Wire.available()) // loop through all but the last
{
char c = Wire.read(); // receive byte as a character
Serial.print(c); // print the character
}
int x = Wire.read(); // receive byte as an integer
Serial.println(x); // print the integer
}
Launchpad:
/** @file sys_main.c * @brief Application main file * @date 17.Nov.2014 * @version 04.02.00 * * This file contains an empty main function, * which can be used for the application. */ /* * Copyright (C) 2009-2014 Texas Instruments Incorporated - <a href="www.ti.com/.../a> * * * 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. * */ /* USER CODE BEGIN (0) */ /* USER CODE END */ /* Include Files */ #include "sys_common.h" /* USER CODE BEGIN (1) */ #include "i2c.h" /* USER CODE END */ /** @fn void main(void) * @brief Application main function * @note This function is empty by default. * * This function is called after startup. * The user can use this function to implement the application. */ /* USER CODE BEGIN (2) */ #define DATA_COUNT 10 #define Master_Address 0x26 #define Slave_Address 0x4 uint8_t TX_Data_Master[10] = { 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19}; uint8_t RX_Data_Master[10] = { 0 }; uint8_t TX_Data_Slave[10] = { 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29}; uint8_t RX_Data_Slave[10] = { 0 }; /* USER CODE END */ void main(void) { /* USER CODE BEGIN (3) */ int repeat = 0; int delay =0; /////////////////////////////////////////////////////////////// // Master Transfer Functionality // /////////////////////////////////////////////////////////////// /* I2C Init as per GUI * Mode = Master - Transmitter * baud rate = 100KHz * Count = 10 * Bit Count = 8bit */ i2cInit(); /* Configure address of Slave to talk to */ i2cSetSlaveAdd(i2cREG1, Slave_Address); /* Set direction to Transmitter */ /* Note: Optional - It is done in Init */ i2cSetDirection(i2cREG1, I2C_TRANSMITTER); for(repeat = 0; repeat < 2; repeat++) { /* Configure Data count */ /* Note: Optional - It is done in Init, unless user want to change */ i2cSetCount(i2cREG1, DATA_COUNT); /* Set mode as Master */ i2cSetMode(i2cREG1, I2C_MASTER); /* Set Stop after programmed Count */ i2cSetStop(i2cREG1); /* Transmit Start Condition */ i2cSetStart(i2cREG1); /* Tranmit DATA_COUNT number of data in Polling mode */ i2cSend(i2cREG1, DATA_COUNT, TX_Data_Master); /* Wait until Bus Busy is cleared */ while(i2cIsBusBusy(i2cREG1) == true); /* Wait until Stop is detected */ while(i2cIsStopDetected(i2cREG1) == 0); /* Clear the Stop condition */ i2cClearSCD(i2cREG1); /* Simple Dealya before starting Next Block */ /* Depends on how quick the Slave gets ready */ for(delay=0;delay<1000000;delay++); }




