Jump to content

Search the Community

Showing results for tags 'read'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • News
    • Announcements
    • Suggestions
    • New users say Hi!
  • Spotlight!
    • Sponsor Spotlight
    • Sponsor Giveaways
  • Energia
    • Energia - MSP
    • Energia - TivaC/CC3XXX
    • Energia - C2000
    • Energia Libraries
  • MSP Technical Forums
    • General
    • Compilers and IDEs
    • Development Kits
    • Programmers and Debuggers
    • Code vault
    • Projects
    • Booster Packs
    • Energia
  • Tiva-C, Hercules, CCXXXX ARM Technical Forums
    • General
    • SensorTag
    • Tiva-C, Hercules, CC3XXX Launchpad Booster Packs
    • Code Vault
    • Projects
    • Compilers and IDEs
    • Development Kits and Custom Boards
  • Beagle ARM Cortex A8 Technical Forums
    • General
    • Code Snippets and Scripts
    • Cases, Capes and Plugin Boards
    • Projects
  • General Electronics Forum
    • General Electronics
    • Other Microcontrollers
  • Connect
    • Embedded Systems/Test Equipment Deals
    • Buy, Trade and Sell
    • The 43oh Store
    • Community Projects
    • Fireside Chat
  • C2000 Technical Forums
    • General
    • Development Kits
    • Code Vault
    • Projects
    • BoosterPacks

Calendars

There are no results to display.


Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Website URL


Location


Interests


Sparkfun


Github

Found 4 results

  1. Dmaseko

    MSP430G2553 ADC

    Hi, I'm new to MSP430, I'm using a MSP430G2553 in a project and need help with an in depth understanding of programming the ADC10 inputs of the MCU. I'm using a potentiometer in order to light one of 3 LEDs. For example, LED1 lights up when input voltage is 1V or less, LED2 lights up between 1V and 2V and LED3 lights up when the input voltage is greater than or equal to 2V. I have attached my code below but I am not clear on how to read, convert and store a voltage so that I can use the IF statements to light the respective LEDs. #include <msp430g2553.h> void indicator_LED(); int main(void) { unsigned int i; WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer P1DIR = 0x00; P2DIR = 0xff; P1OUT = 0x00; P2OUT = 0x00; while(1) // keep looping { ADC10CTL1 = CONSEQ_2 + INCH_0; // Repeat single channel, A0 ADC10CTL0 = ADC10SHT_2 + MSC + ADC10ON + ADC10IE; // Sample & Hold Time + ADC10 ON + Interrupt Enable ADC10DTC1 = 0x0A; // 10 conversions ADC10AE0 |= 0x01; // P1.0 ADC option select ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start __low_power_mode_0(); //__bis_SR_register (CPUOFF + GIE);// LPM0, ADC10_ISR will force exit if (ADC10MEM <= 0x228 && ADC10MEM > 0x1D6) { P2OUT = P2OUT | BIT1; for(i=0;i<=1;i++); } else if (ADC10MEM <= 0x1D6) { P2OUT = P2OUT | BIT2; for(i=0;i<=1;i++); } else if (ADC10MEM > 0x228) { P2OUT = P2OUT | BIT0; for(i=0;i<=1;i++); } else { P2OUT = ~P2OUT; for(i=0;i<=1;i++); } } }
  2. I have an XBee (S2C) connected to my Mac and another XBee connected to a TI microcontroller (TIVA-C129) communicating with each other - Mac as a coordinator and TI as a router. I can communicate between them, but on the TI side, I can't read the exact data that is coming in the serial port. On the Mac, I am running below python code that reads the incoming serial data through XBee and writes an acknowledgment. #!/usr/bin/python import serial ser = serial.Serial('/dev/tty.usbserial-A104IC2U', 9600) ack='A' while True: incoming = ser.readline().strip() if incoming != 'A': print '%s' % incoming ser.write('%s\n' % ack) On the TI side, I have below code int incomingByte = 0; void setup() { Serial3.begin(9600); //UART3 has XBee connection pinMode(LED, OUTPUT); } void loop() { Serial3.println("Sending command to the XBee"); delay(1000); Serial3.println("I am R1"); delay(1000); if (Serial3.available() > 0) { // read the incoming byte from UART3 incomingByte = Serial3.read(); // say what you got, print at the usb serial console Serial.print("I received: "); Serial.println(incomingByte, DEC); } } When I run this, XBee communication stops after printing "I am R1" in the python console. I am sure Serial3.available() > 0 is working as when I replace it with a blink code like below, it works and XBee communication keeps working on. if (Serial3.available() > 0) { digitalWrite(LED, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(LED, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second } So looks like the problem is in incomingByte = Serial3.read(); From python, I am sending a string (%s) with ser.write('%s\n' % ack). Is Serial3.read() the right read mechanism for the ack string? Anything else? FYI: I tested the serial.read() only with TI (no python involved) by writing something in the console and serial.read() can read and print it.
  3. Hi! Just a few questions: What is the default reference voltage for the analogRead() function on a msp430 g2553 ? Is it the internal Vcc ? How can I read the exact reference voltage correctly? Is there an option to change the reference voltage? Thanks in advance! kind regards, s1ck
  4. yspede

    i2c read ?

    Hello. im trying to read from the i2c port on my g2231, i have found a i2c libary from this website link but as I see the libary dont support repeated start. I have tried to add this, with some code I found on this forum. im trying to read from a expander ic MCP23016. but the only thing I read is 0xFF ?. im able to write to the expander ic with no problem. its the first time i work with i2c. thanks for looking I have added the full code to. void main(void) { WDTCTL = WDTPW + WDTHOLD; __delay_cycles(500000); i2c_init(); // startup i2c exint(); // init the expander ic lcdint(); // init the lcd display on the expander ic lcdsendd(0x48); // H lcdsendd(0x45); // E lcdsendd(0x4C); // L lcdsendd(0x4C); // L lcdsendd(0x4F); // O ////////////////////////////////////// reading /////////////////////////////////////////////// i2c_start(); i2c_write8(0x20 << 1); // expander ic port write i2c_write8(0x01); // point on port 1 i2c_rpt(); // repeated start bit i2c_write8(0x21 << 1); // the read address readreg = i2c_read8(0x00); readreg = i2c_read8(0x00); i2c_stop(); lcdsendd(readreg); // write the output the the lcd display. lcdsendd(readreg1); this is the i2c libary //code adapted from http://www.43oh.com/forum/viewtopic.php?f=9&t=139 //Kerry D. Wong //http://www.kerrywong.com #include "i2c.h" #include <msp430g2231.h> #define SDA BIT7 //P1.7 #define SCL BIT6 //P1.6 #define LED BIT0 //P1.0 void i2c_init(void) { P1DIR |= SCL | SDA | LED; // Set SCL, SDA and LED as Output P1REN |= SCL | SDA; // Set Pull-Ups on SCL and SDA // enable SDA, SCL, SCLK, i2c mode, MSB, output enabled, hold in reset USICTL0 = USIPE7 | USIPE6 | USIMST | USIOE | USISWRST; // USICTL0 Upper 8bit Register of 16bit USICTL Register // USIPE7 = P1.7 USI Mode, i2c SDA enabled // USIPE6 = P1.6 USI Mode, i2c SCL enabled // USIPE5 = P1.5 USI Mode, i2c Clock Input? (Not Set) // USILSB = LSB Mode (Not Set = MSB) // USIMST = Master Mode // USIGE = Output Latch (Not Set = Clock Controlled) // USIOE = Data Output Enable // USISWRST = USI Software Reset (Set to allow changing settings) // SMCLK / 4, and Reverse Clock Polarity USICKCTL = USIDIV_2 + USISSEL_2 + USICKPL; // USICKCTL 8bit USI Clock Control Register // USIDIVx = Clock Divider (Bit7-5, USIDIV_2 = Divide by 4) // USISSELx = Clock Source (For Master Mode, Bit4-2, USISSEL_2 = SMCLK) // USICKPL = Clock Polarity (0 = Inactive Low, 1 = Inactive High) // USISWCLK = Software Clock State // I2C Mode USICTL1 = USII2C; // USICTL1 Lower 8bit Register of 16bit USICTL Register // USICKPH = Clock Phase (0 = Data Changed, then Captured, 1 = Data Captured, then Changed) // USII2C = I2C mode // USISTTIE = START condition Interrupt // USIIE = USI Counter Interrupt // USIAL = Arbitration Lost Notification // USISTP = STOP condition Notification // USISTTIFG = START condition Int. Flag // USIIFG = USI Counter Int. Flag // release from reset USICTL0 &= ~USISWRST; } void i2c_start(void) { P1OUT |= LED; // Turn P1.0 Led on // Send i2c START condition USISRL = 0x00; // Load USISRL Lower Byte Shift Register MSB with 0 for i2c START USICTL0 |= USIGE | USIOE; // Force Output Latch, And Enable Data Output Bit (High to Low SDA while SCL is High) USICTL0 &= ~USIGE; // Clear Output Latch (Return to Clock Control) } void i2c_stop(void) { // Prepare i2c STOP condition USICTL0 |= USIOE; // Enable Data Output Bit (Turn SDA into Output) USISRL = 0x00; // Load USISRL Lower Byte Shift Register MSB with 0 for i2c STOP USICNT = 1; // Load USICNT Counter with number of Bits to Send. USIIFG Auto-Cleared // Data TXed by USI I2C while((USICTL1 & USIIFG) != 0x01); // Delay, Wait for USIIFG, Counter down to 0 // Send i2c STOP condition USISRL = 0xFF; // Load USISRL Lower Byte Shift Register MSB with 1 for i2c STOP USICTL0 |= USIGE; // Force Output Latch (Low to High SDA while SCL is High) USICTL0 &= ~USIOE & ~USIGE ; // Clear Data Output Enable Bit and Output Latch (Release SCL) P1OUT &= ~LED; // Turn P1.0 Led off } unsigned char i2c_write8(unsigned char c) { // TX USICTL0 |= USIOE; // Enable Data Output Bit (Turn SDA into Output) USISRL = c; // Load USISRL Lower Byte Shift Register with 8 Bit data (Byte) USICNT = 8; // Load USICNT Counter with number of Bits to Send. USIIFG Auto-Cleared // Data TXed by USI I2C while((USICTL1 & USIIFG) != 0x01); // Delay, Wait for USIIFG, Counter down to 0 // RX // Data TXed. Ready to Receive (n)ACK from i2c Slave USICTL0 &= ~USIOE; // Clear Data Output Enable Bit (Turn SDA into Input) USICNT = 1; // Load USICNT Counter with number of Bits to Receive. USIIFG Auto-Cleared // Data RXed by USI I2C while((USICTL1 & USIIFG) != 0x01); // Delay, Wait for USIIFG, Counter down to 0 // Return Data c = USISRL; // LSB of USISRL Holds Ack Status of 0 = ACK (0x00) or 1 = NACK (0x01) return c; } unsigned char i2c_read8(unsigned char acknack) { // RX USICTL0 &= ~USIOE; // Clear Data Output Enable Bit (Turn SDA into Input) USISRL = 0x00; // Clear USISRL Lower Byte Shift Register (Byte) USICNT = 8; // Load USICNT Counter with number of Bits to Receive. USIIFG Auto-Cleared // Data RXed by USI I2C while((USICTL1 & USIIFG) != 0x01); // Delay, Wait for USIIFG, Counter down to 0 // Copy Data to c unsigned char c; c = USISRL; // USISRL Holds Received Data // TX // Data RXed. Ready to Send (n)ACK to i2c Slave USICTL0 |= USIOE; // Enable Data Output Bit (Turn SDA into Output) USISRL = acknack; // Load USISRL Lower Byte Shift Register MSB with acknack (0x00 = Ack, 0xFF = Nack) USICNT = 1; // Load USICNT Counter with number of Bits to Send. USIIFG Auto-Cleared // Data TXed by USI I2C while((USICTL1 & USIIFG) != 0x01); // Delay, Wait for USIIFG, Counter down to 0 // Return Data return c; } void i2c_rpt(void) { USICTL0 |= USIOE; USISRL = 0xFF; USICNT = 1; while ( ( USICTL1 & USIIFG ) != 0x01 ); USICTL1 &= ~USIIFG; // likely not needed __delay_cycles( 100 ); USISRL = 0x00; USICTL0 |= USIGE + USIOE; USICTL0 &= ~USIGE; __delay_cycles( 100 ); } i2c.c i2c.h main.c
×
×
  • Create New...