Simple Digital IO. This should be simple.

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

Please tell me something here is wrong:

MCUCR = 0b00000000;
DDRA = 0b00000000;
PORTA = 0b11111111;

...

while(1) uartPrintNum((int) PINA,'b');

uartPrintNum converts a number into a string, in this case 'b'inary. If I don't touch the pins, they read 0. If I force them high physically, I read 0. Have I gone insane?

Cheers!

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

What is the processor that you have all the MCUCR set to 0?
Port a is set to all inputs

Wheres the rest of your code?

I am assuming you are running this in simulator and not real world?

The answer is there are too many pieces of your puzzle missing to 100% confirm you are insane

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

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

Very well, I suppose its short as is:

/*
 * testC01.c
 *
 * Created: 21/02/2012 7:36:20 PM
 *  Author: t
 */ 

#include "global.h"

#include 		// include I/O definitions (port names, pin names, etc)
#include 	// include interrupt support
#include 
#include 

#include "uart.h"

int main(void)
{
	init();
	
    while(1)
    {
		uartPrintNum((int) MCUCR,'b'); uartSendString("\n\r");
		uartPrintNum((int) PORTA,'b'); uartSendString("\n\r");
		uartPrintNum((int) DDRA,'b'); uartSendString("\n\r");
		uartPrintNum((int) PINA,'b'); uartSendString("\n\r");
		uartPrintNum((int) PIND,'b'); uartSendString("\n\r");
		
		_delay_ms(500);
		uartSendString("\033[2J");
		uartSendString("\033[0;0H");
    }
}

void init()
{
	uartInit('n',9600);
	
	MCUCR = 0b00000000;
	DDRA = 0b00000000;
	PORTA = 0b11111111;
	
	DDRD &= ~(1<<PD6);
	PORTD |= (1<<PD6);
}

Just added that PORTD D stuff and it works fine. What could be the problem? (the port D input works when I physically toggle it. the port A ones dont)......... and this is a mega644

Last Edited: Wed. Feb 22, 2012 - 03:38 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A lot of AVR's have the ADC on PortA, which requires that AVCC be tied to VCC to power PortA. Is this the case for your AVR and do you have AVCC wired to VCC?

edit: Ok a 644 has the ADC on PortA so you need to tie AVCC to VCC.

Last Edited: Wed. Feb 22, 2012 - 03:43 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes sir, I have AVCC tied to VCC tied to 5V.

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

Interesting... is it possible for the whole port to just "die"?

DDRA = 0b11111111;
PORTA = 0b11111111;

This initialization also results in the PINA register read as all zeros.

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

Indeed this is the problem. Just tried another chip. There goes ten bucks. Thanks for letting me speak my problem out loud and thanks for listening :)

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

Quote:
the port A ones dont

So what do you get all 0's or all 1's.

You might try going a little more basic after making all of PORTD outputs & check PORTD following PORTA with a logic probe when you toggle PORTA inputs.

   DDRD=0xff;
   while(1)
      PORTD=PINA; 

Charles Darwin, Lord Kelvin & Murphy are always lurking about!
Lee -.-
Riddle me this...How did the serpent move around before the fall?

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

All zeros baby!

I could, but I would see this as being redundant since I'm reading the value directly anyways. Plus if PORTD were also broken, then I may accumulate points of failure. On the bright side, I know my UART works. Thanks for the tips!

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

Quote:
but I would see this as being redundant

I see a KISS technique, as using common sense!

Charles Darwin, Lord Kelvin & Murphy are always lurking about!
Lee -.-
Riddle me this...How did the serpent move around before the fall?

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

I guess simple here is a matter of opinion. No doubt your method works as well as mine - I also introduce the point of failure of the UART module. However, it is the first thing I ever set up (for future debugging purposes), and therefore already knew it worked.

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

Whatever!

Charles Darwin, Lord Kelvin & Murphy are always lurking about!
Lee -.-
Riddle me this...How did the serpent move around before the fall?

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

I'd still suspect AVcc/AGND.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

Are you certain? I tried three different chips with equivalent code and physical setup and only the one didn't work. Why might you suggest a problem still exists on the connections themselves?

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

Quote:
I tried three different chips with equivalent code and physical setup and only the one didn't work.

It would have been pertinant to mention that before!
Obviously you have a faulty MCU!

Charles Darwin, Lord Kelvin & Murphy are always lurking about!
Lee -.-
Riddle me this...How did the serpent move around before the fall?

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

Quote:

Obviously you have a faulty MCU!

Or one AVR with scr*wed-up fuses.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

Quote:
Indeed this is the problem. Just tried another chip. There goes ten bucks.
:)