This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28027F: TMS320F28027F

Part Number: TMS320F28027F

Tool/software:

HI iam working on i2c interface using bmp280 sensor while scaning i2c scanner iam not getting i found  please check below code for sda32,scl33 iam using

/*BMP280 barometric pressure and temperature sensor C Driver*/
/*Reza Ebrahimi - https://github.com/ebrezadev */
/*Version 1.0*/

#include "bmp280.h"
#include "sci.h"
//#include "DSP28x_Project.h"

/* Writes an array (data[]) of arbitrary size (dataLength) to I2C address (deviceAddress),
starting from an internal register address (startRegisterAddress) */
void bmp280_write_array(uint8_t deviceAddress, uint8_t startRegisterAddress, uint8_t *data, uint8_t dataLength)
{
uint8_t i;
EALLOW;

// Enable I2C0 for writing
I2caRegs.I2CMDR.bit.IRS = 1; // Set to idle state
I2caRegs.I2CSAR = deviceAddress; // Set I2C device address
I2caRegs.I2CCNT = dataLength + 1; // Set number of bytes to send (register + dataLength)

// Write start register address
I2caRegs.I2CDXR = startRegisterAddress;

for (i = 0; i < I2caRegs.I2CCNT; i++) {
I2caRegs.I2CDXR = data[i]; // Write the data byte
}

// Start the I2C communication
I2caRegs.I2CMDR.bit.IRS = 0; // Initiate the transfer
if (I2caRegs.I2CSTR.bit.BB == 1) {

}
if (I2caRegs.I2CSTR.bit.SCD == 1) {

}


EDIS;
}

void bmp280_read_array(uint8_t deviceAddress, uint8_t startRegisterAddress, uint8_t *data, uint8_t dataLength)
{
uint8_t i;
uint32_t timeout = 200000; // Set a higher timeout for read operation

EALLOW;

// Step 1: Write the register address (e.g., 0xD0 for chip ID)
bmp280_write_array(deviceAddress, startRegisterAddress, NULL, 0); // Write operation to select the register

// Step 2: Perform a repeated start (restart the I2C bus to prepare for reading)
I2caRegs.I2CMDR.bit.STT = 1; // Initiate a restart condition (repeated start)

// Wait for the I2C communication to complete
timeout = 10000; // Set timeout for wait after start condition
while (I2caRegs.I2CSTR.bit.BB == 1 && timeout > 0) { // Wait for the bus to be free (BB = bus busy)
timeout--;
}

if (timeout == 0) {
scia_msg("\r\nI2C bus busy, cannot start read operation.\0");
EDIS;
return;
}

// Step 3: Set up the I2C communication for reading data
I2caRegs.I2CSAR = deviceAddress; // Set I2C device address
I2caRegs.I2CCNT = dataLength; // Set number of bytes to read
I2caRegs.I2CMDR.bit.IRS = 1; // Start I2C communication for read operation

// Step 4: Wait for the data to be ready and read the data byte by byte
for (i = 0; i < I2caRegs.I2CCNT; i++) {
timeout = 200000; // Adjust timeout limit as needed

// Wait for data to be ready
while (I2caRegs.I2CSTR.bit.RRDY != 1 && timeout > 0) {
timeout--;
}

if (timeout == 0) {
scia_msg("\r\nRead operation timeout.\0");
EDIS;
return;
}

// Read the data from the I2C data register
data[i] = I2caRegs.I2CDRR;
}

// Step 5: End of I2C read operation
scia_msg("\r\nRead operation successful.\0");
EDIS;
}

void I2C_Init(void)
{
// Initialize I2C0
I2caRegs.I2CFFTX.bit.TXFFIENA = 0; // Disable the FIFO during setup

I2caRegs.I2CFFRX.bit.RXFFIENA = 0;
//I2caRegs.I2CMDR.bit.IRS = 1; // Reset I2C module
I2caRegs.I2CMDR.bit.STP = 1; // Stop I2C communication

// Configure the I2C baud rate (assuming 100kHz)
I2caRegs.I2CCLKL = 100; // Set the low period for baud rate
I2caRegs.I2CCLKH = 100; // Set the high period for baud rate

// Set master mode and enable I2C
I2caRegs.I2CMDR.bit.MST = 1; // Set I2C as master mode
I2caRegs.I2CMDR.bit.IRS = 0; // Start the I2C communication
// I2caRegs.I2CSTR.all = 0x0000; // Clear the interrupt status register

I2caRegs.I2CFFTX.bit.TXFFIENA = 1; // Enable FIFO again
I2caRegs.I2CFFRX.bit.RXFFIENA = 1;
}
void I2C_Scanner(void)
{
uint8_t deviceAddress;
for (deviceAddress = 1; deviceAddress < 220; deviceAddress++)
{
// Try to initiate a start condition for the given address
I2caRegs.I2CMDR.all = 0; // Clear previous settings
I2caRegs.I2CSTR.all = 0; // Clear previous flags
I2caRegs.I2CCNT = 1; // Set number of bytes to be transferred (1 byte)

I2caRegs.I2CDXR = deviceAddress; // Write device address
I2caRegs.I2CMDR.bit.STT = 1; // Initiate start condition

// Wait for the transaction to complete
while (I2caRegs.I2CSTR.bit.BB == 1) {} // Wait for bus to be free

// Check if the device responded
if (I2caRegs.I2CSTR.bit.NACK == 0)
{
deviceAddress;
}
else
{

}
}
}
/* A delay function for milliseconds delay */
void delay_function(uint32_t delayMS)
{
uint32_t i;
for (i = 0; i < delayMS * 1000; i++) {
asm(" NOP"); // No operation (to create a small delay)
}
}

/* Implements a power function (used in altitude calculation) */
float power_function(float x, float y)
{
return power_function(x, y);
}
// Function to scan I2C devices