How to use PB2 on ATMEGA644PA as a software UART RX PIN?

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Note: I am new to avr programming. I know C and C++ but haven't gone outside programming an Arduino, it's my first attempt.

I have been testing all of my code with a break out board http://wiki.microduinoinc.com/Mi...

This board had a bootloader on it.

I bought another one and wiped the bootloader to test it without one.

 

The Problem:

I have a GPS that I plan on implementing on my existing design.

  • My ATMEGA644PA already has filled its two hardware serial ports. (one for serial to the computer and one to a modem)
  • I want to use pin PB2 as a serial port because it has interrupt capability.
  • I want to use something like SoftwareSerial library from arduino. But I do not want to use the Arduino IDE anymore nor a bootloader.
  • When I used a bootloader +ide, the SoftwareSerial library worked fine and I was able to read the gps data.
  • When using avr-gcc/avr-g++ to compile it does not read out the data. The library compiles without errors.
  • I have been using avrdude to upload to the chip via ICSP.
  • Is there any code out there that will let me read in serial data for PB2?

Any help is appreciated.

Thanks

 

 

This topic has a solution.
Last Edited: Wed. Dec 12, 2018 - 08:36 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

joshagirgis wrote:
When using avr-gcc/avr-g++ to compile it does not read out the data. The library compiles without errors.

Since most Arduino's run at 16MHz, it's probably a timing issue, what is your clock source and at what speed.  Are you sure?

 

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Forgive me if I answer this wrong.

clock:16MHz

trying to read the serial port at baud rate:9600 

In the compiler I present this argument

-DF_CPU=16000000UL

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

First which speed of the AVR and the related baud rate ?

 

If not to fast a communication I would place the RX routine in a timer interrupt there run something like 5 times faster then the baud rate.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

joshagirgis wrote:
clock:16MHz trying to read the serial port at baud rate:9600 In the compiler I present this argument -DF_CPU=16000000UL

 

Ok, how have you proven your avr is running at 16MHz?  

What else is running on your AVR? Could that be blocking the interrupt? (i.e. do you disable interrupts with in your code, or use another interrupt?)

 

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am not running anything else on the chip. other than trying to read the PB2 pin.

 

Not sure how I would confirm the 16MHz. This is very new to me.

Attached is the library I am using written by Nick Gammon. Its software serial but only for reading from RX interrupt driven pin.

Since I haven't been immersed to avrs whatsoever I started by using some of the arduino libraries as well, such as HardwareSerial.

at the risk of looking like an idiot, here is my code:


#include <Arduino.h>
#include <ReceiveOnlySoftwareSerial.h>

ReceiveOnlySoftwareSerial gpsSer(PB2); // RX

int main(void){
  init();
  Serial.begin(9600);
  gpsSer.begin(9600);
  Serial.println("Start");
 
  for (;;) {
  char c = gpsSer.read();
  Serial.write(c);
  delay(2000);
  }
  return 0;
}    

 

Attachment(s): 

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think I have found the problem. I can now read some gps data

Since using the arduino libraries my pin mapping is all crapped up. the pins_arduino.h file screws things up

This portion of the library uses digitalPinToBitMask,  digitalPinToPort, portInputRegister I set port to PB2 and it fixed it. However these functions are not working in the Arduino.h and pins_arduino.h file. not sure what the deal is


void ReceiveOnlySoftwareSerial::setRX(uint8_t rx)
{
  pinMode(rx, INPUT);
  if (!_inverse_logic)
    digitalWrite(rx, HIGH);  // pullup for normal logic!
  _receivePin = rx;
  _receiveBitMask = digitalPinToBitMask(rx);
  uint8_t port = digitalPinToPort(rx);
  _receivePortRegister = portInputRegister(port);
}

 

Last Edited: Wed. Dec 12, 2018 - 07:43 PM