Jump to content

Search the Community

Showing results for tags 'write'.



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. Hello, I am using example code of energia Pfatfs library named "PFatFsfileTest". This program reads "T_READ.txt" file from sd card properly. But It can't write string "Hello world" 10 times to the file "T_WRITE.txt" into sd card. Instead, it just writes only "H". I am posting the original code of file below: /*----------------------------------------------------------------------*/ /* Petit FatFs sample project for generic uC (C)ChaN, 2010 */ /*----------------------------------------------------------------------*/ /* ported to Energia */ /* copy the two files t_read.txt and t_write.txt from the example folder in the root of the sd card*/ #include "SPI.h" #include "pfatfs.h" #define cs_pin 10 // chip select pin #define read_buffer 128 // size (in bytes) of read buffer unsigned short int bw, br;//, i; char buffer[read_buffer]; int rc; DIR dir; /* Directory object */ FILINFO fno; /* File information object */ void setup() { pinMode(PUSH2, INPUT_PULLUP); Serial.begin(9600); // initialize the serial terminal FatFs.begin(cs_pin); // initialize FatFS library calls } void die ( /* Stop with dying message */ int pff_err /* FatFs return value */ ) { Serial.println();Serial.print("Failed with rc=");Serial.print(pff_err,DEC); for (; ; } /*-----------------------------------------------------------------------*/ /* Program Main */ /*-----------------------------------------------------------------------*/ void loop() { Serial.println(); Serial.println("Press button to start..."); while(digitalRead(PUSH2)==1){} delay(100); while(digitalRead(PUSH2)==0){} Serial.println(); Serial.println("Open a test file (t_read.txt)."); delay(100); rc = FatFs.open("T_READ.TXT"); if (rc) die(rc); Serial.println(); Serial.println("Type the file content."); delay(100); for (; { rc = FatFs.read(buffer, sizeof(buffer), &br); /* Read a chunk of file */ if (rc || !br) break; /* Error or end of file */ for (uint16_t i = 0; i < br; i++) /* Type the data */ Serial.print(buffer[i]); delay(100); } if (rc) die(rc); Serial.println(); Serial.println("Open a file to write (t_write.txt)."); delay(100); rc = FatFs.open("T_WRITE.TXT"); if (rc) die(rc); Serial.println(); Serial.println("Write a text data. (10 x Hello world!)"); delay(100); bw=0; for (uint16_t i=0;i<10;i++) { rc = FatFs.write("Hello world!\r\n", 14, &bw); if (rc || !bw) break; } if (rc) die(rc); rc = FatFs.write(0, 0, &bw); //Finalize write if (rc) die(rc); delay(100); Serial.println(); Serial.println("Verify the write process (t_write.txt)."); delay(100); rc = FatFs.open("T_WRITE.TXT"); if (rc) die(rc); Serial.println(); Serial.println("Type the file content."); delay(100); for (; { rc = FatFs.read(buffer, sizeof(buffer), &br); /* Read a chunk of file */ if (rc || !br) break; /* Error or end of file */ for (uint16_t i = 0; i < br; i++) /* Type the data */ Serial.print(buffer[i]); delay(100); } if (rc) die(rc); Serial.println(); Serial.println("Open root directory."); delay(100); rc = FatFs.opendir(&dir, ""); if (rc) die(rc); Serial.println(); Serial.println("Directory listing..."); delay(100); for (; { rc = FatFs.readdir(&dir, &fno); /* Read a directory item */ if (rc || !fno.fname[0]) break; /* Error or end of dir */ if (fno.fattrib & AM_DIR) {Serial.print("<dir>\t"); Serial.println(fno.fname);delay(100);} else {Serial.print(fno.fsize);Serial.print("\t"); Serial.println(fno.fname);delay(100);} } if (rc) die(rc); Serial.println(); Serial.print("Test completed."); //for (; ; } and i am also posting my terminal output below: Press button to start... Open a test file (t_read.txt). Type the file content. abc Open a file to write (t_write.txt). Write a text data. (10 x Hello world!) Verify the write process (t_write.txt). Type the file content. H Open root directory. Directory listing... 3 T_READ.TXT 3858759679 m 3842012416 N 1409286144 EWTEX~1T.XT Test completed. Press button to start... Plz tell me the solution as soon as possible.
  2. 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++); } } }
  3. asdf2as144

    aiiiiiiiiiiii

    ..............................
  4. I am working on the MSP430G2553 using I2C and Serial libraries. I am playing right now to try to understand the usage of the libraries. I have an I2C slave that I am trying to control how much data gets returned when a read is executed. Using the serial interface I can increase the size that is sent over the I2C but I can't reduce the size even though the variable passed to Wire.write shows it has reduced. Slave code: #include <Wire.h> #define MY_ADDR 2 #define ERR_RQST_MSB 0xF0 ///< First byte sent when request hasn't been preceded by a value #define ERR_RQST_LSB 0x00 ///< Second byte sent when request hasn't been preceded by a value #define EXPECT_RQST_SIZE 2 ///< Expected size for any data request #define RSPNS_SIZE 2 ///< How many to send back for any request #define MONITOR_BAUD 38400 ///< Baud rate for monitor interface #define MIN_CMD 0 ///< Minimum valid command #define MAX_CMD 4 ///< Maximum valid command #define RESET_CMD 128 ///< Command to "reset" processor byte sendMSB = ERR_RQST_MSB; byte sendLSB = ERR_RQST_LSB; // Definition of the available one character commands typedef enum CommandList{ clEmpty = '\0', clWrtLen = 'w', clAdr = 'a', clBaud = 'b', }clist; const byte Term1 = (byte)'\r'; const byte Term2 = (byte)'\n'; byte cmd = 0; byte rx = 0; byte tx = 0; byte rxCmdBuf[16] = ""; byte *rxPtr = &rxCmdBuf[0]; bool processingCommand = false; bool newCommand = false; const uint8_t sendBuf[] = "0123456789012345678"; #define MAX_WRT_LEN 16 uint16_t curBaud = MONITOR_BAUD; uint8_t curAdrs = MY_ADDR; volatile uint8_t writeLen = 1; void setup() { Serial.begin(curBaud); // start serial for output Wire.begin(curAdrs); // join i2c bus with MY_ADDR Wire.onRequest(requestEvent); // register event Wire.onReceive(receiveEvent); // register event } void loop() { delay(100); if(tx > 0){ tx = 0; Serial.println("Tx"); } if(rx > 0){ rx = 0; Serial.println("Rx"); } receiveCommand(); processCommand(); } // Bring one command at a time into the buffer void receiveCommand(void) { // If they are processing a command then let new chars sit if(!processingCommand){ // Update the buffer if there is more data while(Serial.available() && !newCommand){ *rxPtr = Serial.read(); //Serial.write((char *)rxPtr); // If any terminating character came in then the command // is complete, mark it as such, otherwise add it to the buffer if((*rxPtr == Term1)||(*rxPtr == Term2)){ *rxPtr++ = 0; newCommand = true; }else{ *rxPtr = (byte)tolower(*rxPtr); rxPtr++; } } } } // Change this to do any special processing of the command void processCommand(void) { static uint16_t lastParm = 0; static byte lastCmd; // If there is anything to do then do it if(newCommand || processingCommand){ if(newCommand){ newCommand = false; lastCmd = rxCmdBuf[0]; lastParm = (uint16_t)strtoul((char *)&rxCmdBuf[1], NULL, 10); } // First character is always the command switch((clist)lastCmd){ case clWrtLen: processingCommand = false; if(lastParm < MAX_WRT_LEN){ writeLen = lastParm; } Serial.println("Write length"); Serial.println(writeLen); break; case clAdr: processingCommand = false; break; case clBaud: processingCommand = false; break; case clEmpty: processingCommand = false; break; default: Serial.println((char *)rxCmdBuf); Serial.println("Please enter a valid command"); processingCommand = false; break; } // Reset the buffer if we are done if(!processingCommand){ rxCmdBuf[0] = 0; rxPtr = &rxCmdBuf[0]; } } } // function that executes whenever data is requested by master // this function is registered as an event, see setup() void requestEvent() { byte len = writeLen; if(len > 15) writeLen = 2; Wire.write(sendBuf, len);//"slave says send something"); // respond with message of 6 bytes tx++; // as expected by master writeLen = 1; } // function that executes whenever data is received from master // this function is registered as an event, see setup() void receiveEvent(int howMany) { while(1 < Wire.available()) // loop through all but the last { char c = Wire.read(); // receive byte as a character Serial.print(c); // print the character } int x = Wire.read(); // receive byte as an integer Serial.println(x); // print the integer rx++; }
×