Author Topic: UART problem with $50 robot  (Read 2629 times)

0 Members and 1 Guest are viewing this topic.

Offline PierreTopic starter

  • Jr. Member
  • **
  • Posts: 47
  • Helpful? 0
UART problem with $50 robot
« on: December 30, 2009, 01:52:19 PM »
I am adding UART functionality to test the photoresistors on the $50 robot.
I am following the UART Tutorial for the $50 robot.

Question One(1).

At this present time, the problem is in the software program.  The compile is fine until I add these lines:

Lines added:

//****************INITIALIZATIONS*******************/
   #uartInit();                // initialize the UART (serial port)
   #uartSetBaudRate(38400);    // set the baud rate of the UART for our debug/reporting output
   #rprintfInit(uartSendByte); // initialize rprintf system

Results:

SoR_Utils.h:51:3: error: invalid preprocessing directive #uartInit
SoR_Utils.h:52:3: error: invalid preprocessing directive #uartSetBaudRate
SoR_Utils.h:53:3: error: invalid preprocessing directive #rprintfInit

  I. Could it be the fuses?  Using the AVR Studio 4 version 4.17 is different then the Tutorial(older version).
 II. Could it be the makefile?
III. How can I have a problem in the initialization?


Greatly appreciated for any advise   

Offline z.s.tar.gz

  • Supreme Robot
  • *****
  • Posts: 540
  • Helpful? 5
  • Linux Guru
Re: UART problem with $50 robot
« Reply #1 on: December 30, 2009, 03:21:21 PM »
I think it's the compiler. It sounds like it's trying to treat uartinit and the others like it does the include directive, but of course they're functions so it doesn't work.
I recommend taking out the # from in front of them and seeing what happens.
Save yourself the typing. Just call me Zach.

Offline PierreTopic starter

  • Jr. Member
  • **
  • Posts: 47
  • Helpful? 0
Re: UART problem with $50 robot
« Reply #2 on: December 30, 2009, 04:17:02 PM »
Thank you z.s.tar.gz

     I think you have find the problem.

     Although I end up with more warning and errors but it is on the wright track.

     I have included a picture of those warnings and errors.  I will try to figure this out.

     
Quote
SoR_Utils.h:51: warning:  data definition has no type or storage class
     
     This one seems easy.  I think I require to declare the variable at first.

Offline rgcustodio

  • Robot Overlord
  • ****
  • Posts: 217
  • Helpful? 0
  • Use "Search" and ye might find answers!
Re: UART problem with $50 robot
« Reply #3 on: December 30, 2009, 07:56:14 PM »
Please check you code.
As far as I can see in the image, the function calls you added are not inside a function. The C pre-processor is trying to process them as a function prototype which they are not thus causing the errors during the compile.

Try to put the new functions you inserted inside the main() function or some other function being called by your main function.
The best thing one can do when it's raining is to let it rain. - H. W. Longfellow

understanding is the path to enlightenment

Offline PierreTopic starter

  • Jr. Member
  • **
  • Posts: 47
  • Helpful? 0
Re: UART problem with $50 robot
« Reply #4 on: December 31, 2009, 05:53:41 PM »
It worked rgcustodio.  Thank you   :)

After compiling.  It mentionned two(2) warnings in the uart.c file.  Since it is for initializing, I hope this will not affect anything.  Here is below the two(2) warning and the file where it is. 

Two(2) Warnings:

uart.c:70: warning: pointer targets in passing argument 2 of 'bufferInit' differ in signedness
uart.c:72: warning: pointer targets in passing argument 2 of 'bufferInit' differ in signedness


uart.c file:

      #ifndef UART_BUFFERS_EXTERNAL_RAM
        // initialize the UART receive buffer
  line 70:   bufferInit(&uartRxBuffer, uartRxData, UART_RX_BUFFER_SIZE);
      // initialize the UART transmit buffer
  line 72:   bufferInit(&uartTxBuffer, uartTxData, UART_TX_BUFFER_SIZE);

Anyone would know why of the two(2) warnings?  ???


Next step are:

2.  I will instal the Hyperterminal and link it to the RS232 Shifter Board
3.  Look at the Hyperterminal reading of the two Photoresistors's sensor( $50 robot )

Offline rgcustodio

  • Robot Overlord
  • ****
  • Posts: 217
  • Helpful? 0
  • Use "Search" and ye might find answers!
Re: UART problem with $50 robot
« Reply #5 on: December 31, 2009, 06:43:02 PM »
Quote
Anyone would know why of the two(2) warnings?

The warning should easily give you a hint of the issue.

Check the function prototype of bufferInit() (it should be in the header file) then check the definition of uartRxData and uartTxData. If you see that one is "unsigned" and the other is not then this mismatch causes the warning.
Signed and unsigned data types do not behave the same since in a signed data type 1-bit of the data type is used as a sign bit. An unsigned data type thus can represent a higher number or value, but can not represent negative values... More info here ... http://en.wikipedia.org/wiki/Integer_(computer_science)

It is good programming practice to always match your data types, specially when passing them as parameters or using them in conditionals (if statements etc).
The best thing one can do when it's raining is to let it rain. - H. W. Longfellow

understanding is the path to enlightenment

Offline PierreTopic starter

  • Jr. Member
  • **
  • Posts: 47
  • Helpful? 0
Re: UART problem with $50 robot
« Reply #6 on: January 01, 2010, 03:12:37 PM »
Problem:
  Hyperterminal is reading number from 14 to 17 but does not read from the PC5(ADC5) of the ATmega8

1. Hyperterminal is functional;
2. Receiving readings from the $50 robot; and
3. Not receiving signal from PC5 pin of the Photoresistor sensor.

Troubleshooting done so far:

A.  Photoresistor Voltage Divider Circuit work fine on the Photoresistor sensor:

   photoresistor: 5-10 Khoms;
            Lights : 2.7 Volts; and
          No light: 1.0 Volt.

B.  Hyperterminal reading:
   
   Photoresistor sensor on:

   - PC5(ADC5): from 14 to 18; and
   - Off PC5  : from 14 to 18.

I think the problem is not in the hardware but in the software.

Using the original Photovore_v1:

Parts of the Photovre codes at the beginning:
Quote
//store sensor data
   sensor_left=a2dConvert8bit(5);
   
Parts of the codes towards the end:
Quote
//rprintf("Initialization Complete\r\n");
      
   //output message to serial (use hyperterminal)
   rprintf("Hello, World! Read My Analog: %d\r\n", sensor_left);

   delay_cycles(2500);//a small delay to prevent crazy oscillations

   
Question I have no answer:

1. Could the problem be that the variable "sennsor_left" is not receiving data?
2. Could "a2dConvert8bit(5)" is not define to pin PC5?

Any help would be really appreciated.  Thank you in advance
« Last Edit: January 01, 2010, 03:14:07 PM by Pierre »

Offline rgcustodio

  • Robot Overlord
  • ****
  • Posts: 217
  • Helpful? 0
  • Use "Search" and ye might find answers!
Re: UART problem with $50 robot
« Reply #7 on: January 01, 2010, 04:33:54 PM »
What specific AVR chip are you using? An ATmega8, same as the one in the 50buck robot?
If you are using a different AVR chip, did you modify the MCU variable in the makefile?

I checked Admin's code from http://www.societyofrobots.com/downloads/sbs_source_photovore_v1.zip
and everything is in order, IMHO. (Saying this after a sleepless night seems scary, if this was an official code review session).
The best thing one can do when it's raining is to let it rain. - H. W. Longfellow

understanding is the path to enlightenment

Offline PierreTopic starter

  • Jr. Member
  • **
  • Posts: 47
  • Helpful? 0
Re: UART problem with $50 robot
« Reply #8 on: January 01, 2010, 05:37:29 PM »
Thank you for the reply rgcustodio

Yes, I am using the AVR ATMega8 chip same as the $50 robot.

I am going step by step with the tutorials i.e.:

     - Step-by-step robot tutorial;
     - Wire connectors;
     - Photoresistor; and
     - UART tutorial.

I will look for any post about ADC output with AVR chip.

rgcustodio thanks for the help.   

 


Get Your Ad Here

data_list