BDCoDE 0 Posted March 26, 2013 Author Share Posted March 26, 2013 I do use Serial.begin(9600) P.S I read this thread and decided to check if it's working on mine board. I connected P1.5 pin to GND and used this code. Still can't receive anything in Serial Monitor. I tried both M430G2553 & M430G2452. What's the problem :x static uint8_t sensorPin = A5; int sensorValue = 0; void setup() { Serial.begin(9600); } void loop() { sensorValue = analogRead(sensorPin); Serial.print(sensorValue); delay(10); } Quote Link to post Share on other sites
roadrunner84 466 Posted March 27, 2013 Share Posted March 27, 2013 I think you should use P1.5 (the 7th pin) instead of P1.7 (the 15th pin). Make sure the jumers are set to hardware serial, not software serial. Quote Link to post Share on other sites
BDCoDE 0 Posted March 27, 2013 Author Share Posted March 27, 2013 Sorry, my fault. I was actually trying with both of them. The problem was in Serial.print(). I used Serial.println() instead. Here is the working source. static uint8_t sensorPin = A5; int sensorValue = 0; void setup() { Serial.begin(9600); } void loop() { sensorValue = analogRead(sensorPin); Serial.println(sensorValue); delay(1000); } But I still can't get this battery test working. Here is the code you gave me, is there anything wrong with it? // Very simple Arduino Lithium-ion battery capacity tester // from electronicsblog.net static uint8_t sensorPin = A5; #define LED GREEN_LED #define resistor 13 float capacity=0, value,voltage,current, time=0; void measure (void) { value= analogRead(sensorPin); voltage=value/1024*5.0; current = voltage/resistor; capacity=capacity+current/3600; time++; Serial.print("Voltage= "); Serial.print(voltage); Serial.print("V Current= "); Serial.print(current); Serial.print("A Capacity= "); Serial.print(capacity); Serial.print("Ah "); Serial.print("Discharging time= "); Serial.print(time); Serial.print("s "); Serial.print("\n"); } boolean x=false; #pragma vector=TIMER0_A0_VECTOR __interrupt void TIMER1_OVF_vect(void) { x=!x; digitalWrite(LED, x); if(x) { measure(); } } void setup() { pinMode(LED, OUTPUT); // I don't know the ATmega timers, but I will be assuming your timer clock is running at 1MHz and interrupts every 0x10000-0x0BDC = 62500 microseconds (every 62.5 milliseconds) _BIS_SR(GIE); // enabled global interrupt; TACTL = TAIE; // enabled timer overflow interrupt; TACTL |= MC_1; // normal operation page 366 (mode up); TACCR0 = 62500 - 1; // set overflow value to remove time error (16bit counter register) TACTL |= TASSEL_2 + TACLR; // start timer/ reset clock Serial.begin(96000); }; void loop () { LPM3; }; Quote Link to post Share on other sites
roadrunner84 466 Posted March 27, 2013 Share Posted March 27, 2013 I added this line of comment // I don't know the ATmega timers, but I will be assuming your timer clock is running at 1MHz and interrupts every 0x10000-0x0BDC = 62500 microseconds (every 62.5 milliseconds) So the timer will be executed every 62.5 ms, not once per second as you intended, use the second piece of code I pasted. Quote Link to post Share on other sites
BDCoDE 0 Posted March 27, 2013 Author Share Posted March 27, 2013 Ok, didn't noticed that part of you message. The code looks like this now: // Very simple Arduino Lithium-ion battery capacity tester // from electronicsblog.net static uint8_t sensorPin = A5; #define LED GREEN_LED #define resistor 13 float capacity=0, value,voltage,current, time=0; void measure (void) { value= analogRead(sensorPin); voltage=value/1024*5.0; current = voltage/resistor; capacity=capacity+current/3600; time++; Serial.print("Voltage= "); Serial.print(voltage); Serial.print("V Current= "); Serial.print(current); Serial.print("A Capacity= "); Serial.print(capacity); Serial.print("Ah "); Serial.print("Discharging time= "); Serial.print(time); Serial.print("s "); Serial.print("\n"); } boolean x=false; #pragma vector=TIMER0_A0_VECTOR __interrupt void TIMER1_OVF_vect(void) { x=!x; digitalWrite(LED, x); if(x) { measure(); } } void setup() { pinMode(LED, OUTPUT); TACTL = ID_3 + MC_1 + TASSEL_2 + TACLR; // Set timer to up mode on SMCLK/8 (125kiHz) TACCTL0 = CCIE; // Enable timer interrupt TACCR0 = 62500 - 1; // set overflow value to remove time error (16bit counter register) _BIS_SR(GIE); // enabled global interrupt; Serial.begin(9600); }; void loop () { LPM3; }; The GREEN_LED is now always ON, but still nothing in Terminal output. Here is the new picture of schematic. There you can see how all jumpers are connected. Quote Link to post Share on other sites
roadrunner84 466 Posted March 27, 2013 Share Posted March 27, 2013 You got rid of the digitalWrite(LED, x); line again... Quote Link to post Share on other sites
BDCoDE 0 Posted March 27, 2013 Author Share Posted March 27, 2013 I tried with now, still no effect. P.S Updated source code in my previous message. Quote Link to post Share on other sites
roadrunner84 466 Posted March 27, 2013 Share Posted March 27, 2013 I must have been sleeping >_< replace this line TACTL = TAIE + MC_3 + TASSEL_2 + TACLR; // Set timer to up mode on SMCLK/8 (125kiHz) with this TACTL = ID_3 + MC_1 + TASSEL_2 + TACLR; // Set timer to up mode on SMCLK/8 (125kiHz) TACCTL0 = CCIE; // Enable timer interrupt Quote Link to post Share on other sites
BDCoDE 0 Posted March 27, 2013 Author Share Posted March 27, 2013 I don't know why, but there is still nothing :shock: P.S Updated source... Quote Link to post Share on other sites
roadrunner84 466 Posted March 27, 2013 Share Posted March 27, 2013 I give up. AFAIK it should be working now. Maybe someone else can take a look. Quote Link to post Share on other sites
BDCoDE 0 Posted March 27, 2013 Author Share Posted March 27, 2013 Let me just ask you a stupid question because I'm REALLY new to all this stuff. How should I receive Serial.print()? Via usual USB cable I use to program the chip using terminal program or via USB2UART converter usin RxD & TxD pins? P.S I'm using M430G2553 chip Quote Link to post Share on other sites
roadrunner84 466 Posted March 27, 2013 Share Posted March 27, 2013 Yes, and then open a terminal program to the virtual com port on your PC. Quote Link to post Share on other sites
BDCoDE 0 Posted March 27, 2013 Author Share Posted March 27, 2013 Edited: I was lucky and received my usb2uart converter now. It's based on CP2102 chip, if it makes any difference. I installed drivers and Windows shows it on COM11 post. I checked the code below, it's working just fine. But not the "Battery Test" code. I have no idea what to do... static uint8_t sensorPin = A5; int sensorValue = 0; void setup() { Serial.begin(9600); } void loop() { sensorValue = analogRead(sensorPin); Serial.println(sensorValue); delay(100); } Checked as well on my another code. This one works fine too. #define cmdL 'L' //UART command #define cmdR 'R' //UART command char incomingByte; // income data char command; void setup() { Serial.begin(9600); } void loop() { if (Serial.available() > 0) { incomingByte = Serial.read(); if(incomingByte == cmdL) { Serial.println("You typed L"); } else if(incomingByte == cmdR) { Serial.println("You typed R"); } else if(incomingByte > '0'){ Serial.println("Wrong command. Please try again"); }// ????? ?????? } delay(100); } Quote Link to post Share on other sites
semicolo 39 Posted March 27, 2013 Share Posted March 27, 2013 What about my my code? It just works I don't think you really need the sampling intervals to be spot on accuracy that you need a timer. If you really want it to be better just do // Very simple Arduino Lithium-ion battery capacity tester // from electronicsblog.net #define LED GREEN_LED #define resistor 6.9 float capacity=0, value,voltage,current, time=0; void measure (void) { value= analogRead(0); voltage=value/1024*5.0; current = voltage/resistor; capacity=capacity+current/3600; time++; Serial.print("Voltage= "); Serial.print(voltage); Serial.print("V Current= "); Serial.print(current); Serial.print("A Capacity= "); Serial.print(capacity); Serial.print("Ah "); Serial.print("Discharging time= "); Serial.print(time); Serial.print("s "); Serial.print("\n"); } boolean x=false; unsigned long ms; void setup() { pinMode(LED, OUTPUT); Serial.begin(9600); ms = millis()+1000; }; void loop () { digitalWrite(LED, x); x=!x; measure(); while (millis() < ms); ms=millis()+1000; }; energia and BDCoDE 2 Quote Link to post Share on other sites
semicolo 39 Posted March 27, 2013 Share Posted March 27, 2013 I mean, the whole goal of using energia/arduino is to not having to play with the registers, else do it in CCS and use the debug feature to find what's wrong. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.