Hello, I am trying to communicate a PCB with the launchpad LAUNCHXL2-TMS57012 through I2C. The code is simple, the launchpad has just to receive and plot what it receives; it is connecter to the PC and with Labview, I see the results. I have tried the communication with an Arduino and it works correctly. With the launchpad, I am not haveing communication. My question is, in Arduino I am using 2 pull-up resistors for the I2C communication; the launchpad seems to be yet pulled up, is it correct or should I use pull-up resistors?
The code I am using is:
/* 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 8
#define Slave_Address 0x50
//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[8] = { 0 };
/* USER CODE END */
void main(void)
{
/* USER CODE BEGIN (3) */
int repeat = 0;
///////////////////////////////////////////////////////////////
// Slave Receiver Functionality //
///////////////////////////////////////////////////////////////
/* I2C Init as per GUI
* Mode = Slave - Receiver
* baud rate = 100KHz
* Count = 10
* Bit Count = 8bit
*/
i2cInit();
/* Configure own address so that master can use it as slave address */
i2cSetOwnAdd(i2cREG1, Slave_Address);
/* Set direction to receiver */
/* Note: Optional - It is done in Init */
i2cSetDirection(i2cREG1, I2C_RECEIVER);
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);
/* Tranmit DATA_COUNT number of data in Polling mode */
i2cReceive(i2cREG1, DATA_COUNT, RX_Data_Slave);
/* 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);
}
fprintf("%c", RX_Data_Slave);
while(1);
}
Meanwhile, the code which is working, used with Arduino is:
#include <Wire.h>
uint8_t data;
int nByte = 0;
byte lectura[4];
unsigned long valor = 0;
void setup()
{
Wire.begin(0x50); // 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 (Wire.available() > 0){ // loop through all but the last
data = Wire.read(); // receive byte as a character
lectura[nByte]=data;
nByte++;
if(nByte % 4 == 0){
nByte = 0;
valor = (unsigned long)lectura[3] + ((unsigned long)lectura[2]<<8) + ((unsigned long)lectura[1]<<16) + ((unsigned long)lectura[0]<<24);
Serial.println(valor);
}
}
}