Hallo,
I have posted 2,3 times before about the i2c communication and succeeded a bit in communication of an IMU and a rm46x.
i were using a "printf" statement to print the data on the screen but it is was very slow. Then i did a uart communicaion to show on uart as well as on console. but whenever i run the code I get the data on uart at the same speed as on the console and whenever i terminate the code from code composer studio i am getting data very fast on the uart as i needed. Why it is behaving like this?
And also when i removed the printf statement i got nothing on the uart.
/*
/* USER CODE BEGIN (0) */
#include "i2c.h"
#include "stdlib.h"
#include "math.h"
#include "sci.h"
int data0,data1;
unsigned char res0[8],res1[8];
/* USER CODE END */
/* Include Files */
#include "sys_common.h"
/* USER CODE BEGIN (1) */
#define ACCEL_SLAVE_ADDR 0x20
#define ACCEL_SLAVE_ADDR1 0x21
#define my_id 0x22
#define XOUT8l 0x42
#define XOUT8h 0x43
//uint8_t RX_Data_Master[1] = {0};
uint8_t sensTemp[1] = {0};
#define i2c1 i2cREG1
/* 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) */
int32_t I2CReceive(int32_t SLAVE_ADDRESS, int8_t reg);
int8_t ReadAccel(int8_t reg);
int8_t ReadAccel1(int8_t reg);
void delay(unsigned int mseconds);
/* USER CODE END */
void main(void)
{
/* USER CODE BEGIN (3) */
uint8 NumberOfChars0,NumberOfChars1, Ax1l,Ax1h,Ax2l,Ax2h;
uint16 valAx1,valAx2;
sciInit();
i2cInit();
while(1){
Ax1l= ReadAccel(XOUT8l);
//printf("Value0: %i\n", Ax1l);
//delay(10);
Ax1h = ReadAccel(XOUT8h);
//printf("Value1: %i\n", Ax1h);
//delay(10);
valAx1 = Ax1h;
valAx1 = (valAx1 <<8) | Ax1l;
NumberOfChars0=ltoa(valAx1,(char *)res0);
sciSend(scilinREG,2,(unsigned char *)"0x");
sciSend(scilinREG,NumberOfChars0,res0);
sciSend(scilinREG,2,(unsigned char *)"\r\n");
//printf("16 bit Value: %i\n", valAx1);
Ax2l= ReadAccel1(XOUT8l);
//printf("Value02: %i\n", Ax2l);
Ax2h = ReadAccel1(XOUT8h);
//printf("Value12: %i\n", Ax2h);
valAx2 = Ax2h;
valAx2 = (valAx2 <<8) | Ax2l;
NumberOfChars1=ltoa(valAx2,(char *)res1);
sciSend(scilinREG,2,(unsigned char *)"1x");
sciSend(scilinREG,NumberOfChars1,res1);
sciSend(scilinREG,2,(unsigned char *)"\r\n");
//printf("16 bit Value222: %i\n", valAx2);
};
/* USER CODE END */
}
/* USER CODE BEGIN (4) */
int32_t I2CReceive(int32_t SLAVE_ADDRESS, int8_t reg)
{
while(i2cIsBusBusy (i2c1) == true);
i2c1->MDR = I2C_RESET_OUT;
i2cSetMode(i2c1, I2C_MASTER);
i2cSetSlaveAdd(i2c1, SLAVE_ADDRESS);
i2cSetDirection(i2c1, I2C_TRANSMITTER);
i2cSetCount(i2c1, 1);
i2cSetStart(i2c1);
while((i2c1->STR & (I2C_TX | I2C_ARDY)) == false); // To wait for the tx ready and register access ready
i2cSendByte(i2c1, reg);
// Start receiving the data from slave
// wait for ARDY before beginning the read phase of the transaction
while((i2c1->STR & I2C_ARDY) == false);
i2c1->MDR = I2C_RESET_OUT; // To set the MDR with I"C is out of reset
i2cSetMode(i2c1, I2C_MASTER);
i2cSetDirection(i2c1, I2C_RECEIVER);
i2cSetCount(i2c1, 1);
i2cSetStart(i2c1);
i2cSetStop(i2c1);
// To receive one byte
uint8 j;
for(j = 0; j < 1; j++)
{
while((i2c1->STR &(I2C_RX | I2C_ARDY)) == true);
sensTemp[j] = i2c1->DRR;
}
while(i2cIsBusBusy (i2c1) == true);
/* Wait until Stop is detected */
while(i2cIsStopDetected(i2c1) == false);
/* Clear the Stop condition */
i2cClearSCD(i2c1);
return sensTemp[0];
}
int8_t ReadAccel(int8_t reg)
{
int8_t accelData = I2CReceive(ACCEL_SLAVE_ADDR, reg);
return accelData;
}
int8_t ReadAccel1(int8_t reg)
{
int8_t accelData1 = I2CReceive(ACCEL_SLAVE_ADDR1, reg);
return accelData1;
}
void delay(unsigned int mseconds)
{
int goal = mseconds + clock();
while (goal > clock());
}
/* USER CODE END */