Jump to content

DavidUser

Members
  • Content Count

    3
  • Joined

  • Last visited

About DavidUser

  • Rank
    Noob Class

Contact Methods

  • Website URL
    http://github.com/DavidUser

Profile Information

  • Github
    http://github.com/DavidUser
  1. Someone can helpme, i'm taking incorrect readings of a magnetometer I believe with the problem are in my i2c code implementation. /* * Print all printable characters on usb channel using UART mode of USCI module * the print is based in busy wait to transfer characters */ #include "msp/msp430g2553.h" void configureDCO(); void configureUART(); void putc(char); void print (const char[]); void print (short); void printStatus(); main() { configureDCO(); configureUART(); UCB0CTL1 = UCSWRST; //Reset USCI UCB0CTL0 = // USCI_B0 control register UCMST // set master mode | UCMODE_3 // I2C mode select | UCSYNC; // synchronous UCB0CTL1 = // UCSI_B0 control register UCSSEL_2 //select clock source, SMCLK | UCSWRST; UCB0I2CSA = 0x1e; // write desired slave address to the UCBxI2CSA, magnetometer address // prescaler to generate 75 Hz (1MHz of SMCLK / 13981 of prescaler) UCB0BR0 = 0x9D; UCB0BR1 = 0x36; //configure ports P1SEL |= BIT6 | BIT7; P1SEL2|= BIT6 | BIT7; UCB0CTL1 &= ~UCSWRST; // Initializate USCI print("[system] I2C configured\r\n"); // send start to transmit UCB0CTL1 |= UCTR // setting UCTR for transmitter mode | UCTXSTT; // setting UCTXSTT to generate START condition // point to register A ( address 0x00 ) while ( !(IFG2 & UCB0TXIFG) ); // wait UCBxTXIFG are set, when set the buffer are empty UCB0TXBUF = 0x00; // load data to be trasmitted on UCBxTXBUF // write 0x78 in register A, mean of eight measurements, 75 Hz sample rate while ( !(IFG2 & UCB0TXIFG) ); // wait UCBxTXIFG are set, when set the buffer are empty UCB0TXBUF = 0x78; // load data to be trasmitted on UCBxTXBUF // point to register B ( address 0x01 ) while ( !(IFG2 & UCB0TXIFG) ); // wait UCBxTXIFG are set, when set the buffer are empty UCB0TXBUF = 0x01; // load data to be trasmitted on UCBxTXBUF // write 0xa0 in register B, gain five while ( !(IFG2 & UCB0TXIFG) ); // wait UCBxTXIFG are set, when set the buffer are empty UCB0TXBUF = 0xa0; // load data to be trasmitted on UCBxTXBUF // point to mode register ( address 0x02 ) while ( !(IFG2 & UCB0TXIFG) ); // wait UCBxTXIFG are set, when set the buffer are empty UCB0TXBUF = 0x02; // load data to be trasmitted on UCBxTXBUF // write 0x00 in mode register, continuous operation while ( !(IFG2 & UCB0TXIFG) ); // wait UCBxTXIFG are set, when set the buffer are empty UCB0TXBUF = 0x00; // load data to be trasmitted on UCBxTXBUF // send stop UCB0CTL1 |= UCTXSTP; // send stop while (UCB0CTL1 & UCTXSTP); // wait STOP condition is ack __delay_cycles(6000); // wait 6ms, until change the settings of magnetometer // send start to receive UCB0CTL1 &= ~UCTR; // setting UCTR for receiver mode UCB0CTL1 |= UCTXSTT; // setting UCTXSTT to generate START condition while (UCB0CTL1 & UCTXSTT); // infinit loop, show continually the measuread values while (true) { // allocate space to the measured values, (x,y,z) coordinates, high byte (h prefix), low byte (l prefix) char hx, lx, hz, lz, hy, ly; // receive data output X MSB register while (!(IFG2 & UCB0RXIFG) ); // wait UCBxRXIFG are set, when set read buffer are full hx = UCB0RXBUF; // load data from buffer to local memory // receive data output X LSB register while (!(IFG2 & UCB0RXIFG) ); // wait UCBxRXIFG are set, when set read buffer are full lx = UCB0RXBUF; // load data from buffer to local memory // receive data output Z MSB register while (!(IFG2 & UCB0RXIFG) ); // wait UCBxRXIFG are set, when set read buffer are full hz = UCB0RXBUF; // load data from buffer to local memory // receive data output Z LSB register while (!(IFG2 & UCB0RXIFG) ); // wait UCBxRXIFG are set, when set read buffer are full lz = UCB0RXBUF; // load data from buffer to local memory // receive data output Y MSB register while (!(IFG2 & UCB0RXIFG) ); // wait UCBxRXIFG are set, when set read buffer are full hy = UCB0RXBUF; // load data from buffer to local memory // receive data output Y LSB register while (!(IFG2 & UCB0RXIFG) ); // wait UCBxRXIFG are set, when set read buffer are full ly = UCB0RXBUF; // load data from buffer to local memory // compose (x, y, z) values short x, y, z; x = (static_cast<short>(hx) << 8) | lx; // compose x MSB and LSB z = (static_cast<short>(hz) << 8) | lz; // compose z MSB and LSB y = (static_cast<short>(hy) << 8) | ly; // compose y MSB and LSB //print (x, y, z) measured values print("( "); print(x); print(", "); print(y); print(", "); print(z); print(" )"); print("\r\n"); } } void configureDCO() { WDTCTL = WDTPW + WDTHOLD; // Stop WDT // Set DCO to 1MHz BCSCTL1 = CALBC1_1MHZ; DCOCTL = CALDCO_1MHZ; __delay_cycles(1000000); } void configureUART() { UCA0CTL1 |= UCSWRST; // put USCI in reset mode // P1.1 = RXD, P1.2=TXD P1SEL |= BIT1 | BIT2; P1SEL2 |= BIT1 | BIT2; UCA0CTL1 |= UCSSEL_3; // Use SMCLK // Set baud rate to 9600 with 1MHz clock (Data Sheet 15.3.13) 1MHz / 104 UCA0BR0 = 104; UCA0BR1 = 0; UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1, correction for the fractional part ( the rest, 9600 - 1MHz / 104) UCA0CTL1 &= ~UCSWRST; // put USCI in operad mode (removing reset mode) /*End configuration hardware UART */ print("[system] uart configured\r\n"); }; void putc(char ch) { while(!(IFG2 & UCA0TXIFG)); UCA0TXBUF = ch; } void print (const char msg[]) { for (int i = 0; msg[i] != '\0'; ++i) putc(msg[i]); } void print (short value) { if (value == 0) { putc('0'); return; } if (value < 0) { putc('-'); value *= -1; } unsigned int size; char buffer[20]; for (size = 0; value; ++size, value /= 10) buffer[size] = value % 10; while (size) putc(buffer[--size] + '0'); } void printStatus() { print("Status:\n\r"); #define __PRINT_STATUS(X, MSG) if (UCB0STAT & X) print(#MSG "! "); __PRINT_STATUS(UCNACKIFG, nack); __PRINT_STATUS(UCALIFG, arbitration lost); __PRINT_STATUS(UCGC, receive general call); __PRINT_STATUS(UCBBUSY, bus busy); __PRINT_STATUS(UCSCLLOW, SCL low); __PRINT_STATUS(UCSTPIFG, stop received); __PRINT_STATUS(UCSTTIFG, start received); print("done\n\r"); } Please this is a old problem, someone can helpme? David Kennedy S. Araujo Computer Engineering Student (PUC GO)
  2. DavidUser

    Need help with I2C using MSP430g2553

    Hi I'm try use this library to msp430g2553 + hmc5883l, at principle to read de ID default on this slave device, my main code use your library but doesn't work /*** USCI master library ************************************************************ In this file the usage of the USCI I2C master library without DMA support is shown. This library uses pointers to specify what data is to be sent. When calling the TI_USCI_I2C_receive or TI_USCI_I2C_transmit routines the number of bytes, which are to be transmitted or received have to be passed as well as a pointer to a data field, that contains(or stores) the data. This code checks if there is a slave with address 0x50 is connected to the I2C bus and if the slave device is present, bytes are received and transmitted. Uli Kretzschmar MSP430 Systems Freising *******************************************************************************/ #include "msp/msp430g2553.h" #include "i2cLib/I2C_MSP430.h" void putc(char ch) { while(!(IFG2 & UCA0TXIFG)); UCA0TXBUF = ch; } void print (const char msg[]) { for (int i = 0; msg[i] != '\0'; ++i) putc(msg[i]); } void print (short value) { if (value == 0) { putc('0'); return; } if (value < 0) { putc('-'); value *= -1; } unsigned int size; char buffer[20]; for (size = 0; value; ++size, value /= 10) buffer[size] = value % 10; while (size) putc(buffer[--size] + '0'); } main() { WDTCTL = WDTPW + WDTHOLD; // Stop WDT // Set DCO to 1MHz BCSCTL1 = CALBC1_8MHZ; DCOCTL = CALDCO_8MHZ; //__delay_cycles(1000000); /* Configure hardware UART */ UCA0CTL1 |= UCSWRST; // put USCI in reset mode // P1.1 = RXD, P1.2=TXD P1SEL = BIT1 + BIT2 ; P1SEL2 = BIT1 + BIT2 ; UCA0CTL1 |= UCSSEL_3; // Use SMCLK // Set baud rate to 9600 with 1MHz clock (Data Sheet 15.3.13) 8MHz / 833 UCA0BR0 = 0x41; UCA0BR1 = 0x03; UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1, correction for the fractional part ( the rest, 9600 - 1MHz / 104) UCA0CTL1 &= ~UCSWRST; // put USCI in operad mode (removing reset mode) /*End configuration hardware UART */ print("[system] UART configured\r\n"); _EINT(); unsigned char deviceAddress = 0x1e; unsigned char prescaler = 0x12; print("searching id...\r\n"); I2CbeginTransmission(deviceAddress); print("[system] transmittion initialized\r\n"); I2Cwrite(0x0a); print("[system] byte transmitted by i2c\r\n"); I2CendTransmission(); char id[3] = {0}; I2CrequestFrom(deviceAddress, 3); print("[system] reception initialized\r\n"); for (int i = 0; i < 3; ++i) { id[i] = I2Cread(); print("[system] byte received by i2c\r\n"); } print("id (decimal): "); for (int i = 0; i < 3; ++i) print(id[i]), print(" "); print("\r\n"); print("id (ASCII): "); for (int i = 0; i < 3; ++i) putc(id[i]), print(" "); print("\r\n"); LPM0; } the program lock on I2CendTransmission. Why it doesn't work? It works with other devices? Someone have a upgrated code?
  3. DavidUser

    C library for MSP430G2553

    I try use this library, but this it's suitable for msp430g2553 device, i do some corrections to work with the msp430g2553, like the SCL SDA pins and port configuration, but persists doesn't working. The msp430g2553 have a Errata Datasheet with big inssures on USCI module I2C Mode, my unique option is read this Errada and try correct the library to msp430g2553 device. If someone have this knowledge please help us. MSP430G2553 Technical Documents: http://www.ti.com/product/MSP430G2553/technicaldocuments
×