Tool/software:
Hi,
I am using MSP microcontroller to read temperature value of "TCN75S" using the "I2C" protocol. There seems to be an issue with my code as the temperature values are not being read even with the code getting executed.
To verify i have used "printf" command but am getting the error message: "../lnk_msp430g2553.cmd", line 93: error #10099-D: program will not fit into available memory, or the section contains a call site that requires a trampoline that can't be generated for this section. run placement with alignment fails for section ".sysmem" size 0x50. Available memory ranges:
RAM size: 0x200 unused: 0xe0 max hole: 0xe0
"../lnk_msp430g2553.cmd", line 94: error #10099-D: program will not fit into available memory, or the section contains a call site that requires a trampoline that can't be generated for this section. run placement with alignment fails for section ".stack" size 0x50. Available memory ranges:
RAM size: 0x200 unused: 0x36 max hole: 0x36
This is my code:
#include <msp430.h>
#include <stdint.h>
#include <stdio.h>
// TCN75S I2C address (7-bit address shifted left by 1)
#define TCN75S_ADDRESS 0x48
void initI2C() {
// Configure I2C pins (P1.6 as SDA, P1.7 as SCL)
P1DIR &= ~(BIT6 | BIT7);
P1SEL |= BIT6 | BIT7;
P1SEL2 |= BIT6 | BIT7;
// Initialize I2C module (UCB0)
UCB0CTL1 |= UCSWRST; // Enable software reset
UCB0CTL0 = UCMST | UCMODE_3 | UCSYNC; // I2C master, synchronous mode
UCB0BR0 = 10; // Set clock divider (adjust as needed)
UCB0BR1 = 0;
UCB0I2CSA = TCN75S_ADDRESS; // Set slave address
UCB0CTL1 &= ~UCSWRST; // Release software reset
}
void writeByte(uint8_t data) {
UCB0TXBUF = data;
while (UCB0STAT & UCBBUSY); // Wait for transmit to complete
}
uint8_t readByte() {
UCB0CTL1 &= ~UCTR; // Change to read mode
UCB0CTL1 |= UCTXSTT; // Generate repeated start condition
while (UCB0CTL1 & UCTXSTT); // Wait for start condition
while (UCB0STAT & UCBBUSY); // Wait for receive to complete
UCB0CTL1 |= UCTXSTP; // Generate stop condition
return UCB0RXBUF;
// Read received data
}
//float readTemperature() {
// writeByte(0x00); // Send temperature register address (0x00)
// return (float)readByte() * 0.5; // Convert to Celsius
int main(void) {
float tempCelsius;
WDTCTL = WDTPW | WDTHOLD; // Stop the watchdog timer
initI2C(); // Initialize I2C communication
while (1) {
writeByte(0x00); // Send temperature register address (0x00)
tempCelsius = (float)readByte() * 0.5; // Convert to Celsius
// Use tempCelsius as needed (e.g., display on LCD, send via UART, etc.)
printf("temperature value is: %f", tempCelsius);
// Add delay or other logic here
}
}
And i am also receiving the issue from below snippet that i am not able generate the start condition:
uint8_t readByte() {
UCB0CTL1 &= ~UCTR; // Change to read mode
UCB0CTL1 |= UCTXSTT; // Generate repeated start condition
while (UCB0CTL1 & UCTXSTT); // Wait for start condition
while (UCB0STAT & UCBBUSY); // Wait for receive to complete
UCB0CTL1 |= UCTXSTP; // Generate stop condition
return UCB0RXBUF;
// Read received data
}
Requesting a sample reference code for this application. Thank you.