I want to send some instruction through rs232 to msp430f247 which inturn communicates with a battery through i2c...(infact smbus and there is a level shifter between battery and msp430f247...) Iam not able to get the output. I want to confirm if my code is correct.
This is my code.
This is my code.
Rich (BB code):
#include <msp430F247.h>
#include "Global_Variables.h"
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
_DINT(); //Disable Interrupt
_NOP();
if (CALBC1_8MHZ ==0xFF || CALDCO_8MHZ == 0xFF) // If calibration constants erased, do not load, trap CPU!!
{
while(1);
}
BCSCTL1 = CALBC1_8MHZ; // Set DCO to 8MHz
DCOCTL = CALDCO_8MHZ;
Init_Module_UART_115200();
Init_I2c();
_EINT(); // Enable interrupts
}
void DeInitI2c(void)
{
UCB1CTL0 &= ~(ENC+UCSYNC); ///// 1) Clear I2C, SYNC, and I2CEN (CLR.B &U0CTL)
UCB1CTL1 |= UCSWRST; ///////2) Set SWRST (MOV.B #SWRST,&U0CTL)
}
void Init_I2c(void)
{
P5SEL |= BIT1+BIT2; // P5.1,P5.2
UCB1CTL0 |= (UCMST + UCMODE_3 + UCSYNC); // Master, I2C mode, Synchronous.
UCB1CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
IE2 |= UCB1RXIE; // Enable RX interrupt
UCB1CTL1 |= (UCSSEL_2 + UCSWRST); // SMCLK, Transmitter, Software reset.
UCB1I2CSA = 0x16; //battery slave
UCB1CTL0 |= USISWRST;
}
void Init_Module_UART_115200(void)
{
UCA1CTL1 |= UCSWRST;
P3SEL |= 0xC0; // P3.6,7 = USCI_A1 TXD/RXD
UCA1CTL1 |= UCSSEL_2; // SMCLK
UCA1BR0 = 69; // 1MHz 115200; (104)decimal = 0x068h
UCA1BR1 = 0; // 1MHz 115200
UCA1MCTL = UCBRS2+ UCBRS1; // Modulation UCBRSx =6
UCA1CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
UC1IE |= UCA1RXIE;
}
#pragma vector=USCIAB1RX_VECTOR
__interrupt void USCIAB1RX_ISR(void){
//while (!(UC1IFG & UCB1TXIFG)); // USCI_B1 TX buffer ready?
while( UCA1RXBUF== 0)
{
}
UCB1TXBUF = UCA1RXBUF;
while( UCB1TXBUF== 0)
{
}
UCA1RXBUF = UCB1TXBUF;// RX -> TXed character
DeInitI2c();
}
/*#pragma vector = USCIAB1TX_VECTOR
__interrupt void USCIAB1TX_ISR(void)
{
RXData = UCB0RXBUF; // Get RX data
__bic_SR_register_on_exit(CPUOFF); // Exit LPM0
}
*/
Last edited by a moderator: