Author Topic: Did any one used baby orangutan lib?  (Read 1955 times)

0 Members and 1 Guest are viewing this topic.

Offline AliaTopic starter

  • Jr. Member
  • **
  • Posts: 12
  • Helpful? 0
Did any one used baby orangutan lib?
« on: March 13, 2011, 07:59:30 PM »
Hi
I am trying to write a code to for serial communication between a module and my baby orangutan. For now I am trying to test my code first with HyperTerminal to make sure it is working. I am using baby orangutan 328p lib for serial communication. All what I need for now is to send bunch of char to baby orangutan. If the right char received in a particular position in an array, LED will be ON otherwise it will be OFF.

I already check another code just to send a char from the baby orangutan to the HyberTerminal and it work. but the receiving part is not working yet.

Code: [Select]
#include <avr/io.h>
#include <util/delay.h>
#include <pololu/orangutan.h>

int main ()
{
   char receive_buffer [2] = {'R','D'};
   DDRC = 0xFF;
   serial_set_baud_rate(115200);

   while (1)
   {   
      serial_receive(receive_buffer ,sizeof(receive_buffer));

      if (receive_buffer [2] == 'A');
         PORTC &= (1 << PC0);
      _delay_ms(5000);       
   }
}





Anyone can tell what is wrong with my code? I will be really grateful.


Offline chuckdaball

  • Jr. Member
  • **
  • Posts: 10
  • Helpful? 0
Re: Did any one used baby orangutan lib?
« Reply #1 on: March 13, 2011, 08:38:20 PM »
Quote
if (receive_buffer [2] == 'A');
         PORTC &= (1 << PC0);
      _delay_ms(5000);

I'm assuming you want to turn ON the LED here?  If so you need to use a bit-wise OR instead of AND, PORTC |= (1 <<PC0). If you are intending of turning it off here you need to PORTC &= ~(1<<PC0). Dunno about the rest of the code, never worked with that API.

Offline joe61

  • Supreme Robot
  • *****
  • Posts: 417
  • Helpful? 16
Re: Did any one used baby orangutan lib?
« Reply #2 on: March 14, 2011, 06:58:23 AM »

Code: [Select]
#include <avr/io.h>
#include <util/delay.h>
#include <pololu/orangutan.h>

int main ()
{
   char receive_buffer [2] = {'R','D'};
   DDRC = 0xFF;
   serial_set_baud_rate(115200);

   while (1)
   {   
      serial_receive(receive_buffer ,sizeof(receive_buffer));

      if (receive_buffer [2] == 'A');
         PORTC &= (1 << PC0);
      _delay_ms(5000);       
   }
}



Calling serial_receive() just starts the process of receiving. When the function returns there may or may not be any bytes in the buffer yet, as it sets up an interrupt handler to receive in the background. I think you want serial_receive_blocking(). See the explanations at http://www.pololu.com/docs/0J18/10

Joe

 


Get Your Ad Here

data_list