NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » ATMega328p Nerdkit programming

January 05, 2011
by weijiajun
weijiajun's Avatar

So I am having an issue with using an ATMega328p chip in my project. The chip I picked up didn't have a bootloader on it, so I picked up a usbasp programmer and installed the bootloader, then I used the usbasp programmer to upload the initialload program and everything seemed to work fine. (I am using a 20Hz crystal as well). However when I try to turn on programming mode (attaching pin 14 to ground) nothing seems to happen. Basically the chip runs just like regular, and I cannot connect to the chip using the supplied USB cord.

I guess I'm just looking for ideas that people might have as to how I should go about finding the problem.

Thanks!

January 05, 2011
by Rick_S
Rick_S's Avatar

If you used the usbasp programmer to send the initialload program you may have overwritten your bootloader. If you want to program the micro with the bootloader, you could probably re-send the bootloader, and make sure the fuses are set properly. Then just use the USB-serial cable from the NK to upload.

Rick

January 05, 2011
by Ralphxyz
Ralphxyz's Avatar

To use the Nerdkit bootloader I believe you have to use the 14.7456MHz crystal supplied with the Nerdkit.

You can program with the 14.7456MHz crystal and then switch crystals to run the program.

Or so it has been said here in the forums.

Ralph

January 05, 2011
by weijiajun
weijiajun's Avatar

Well turns out you were both right. I originally tried to switch between the 20 and the 14.7.. crystal and it hadn't worked for me, but that is because it looks like I was overwritting the bootloader as Rick mentioned.

Thanks for the quick replies!

January 18, 2011
by ramaral
ramaral's Avatar

Hi Guys,

I'm trying to understand the UART. I'm using the libnerdkits library and using the uart functions. All I want to do is send the MCU an aphanumeric string and have it echo it back to me via the USB-to-Serial cable. I'm using termite for my serial client. Here's the heart of the code.

while (1)
{
    c = uart_getchar( uartStream );

    printf_P ( PSTR("c %c \n"), c);  delay_ms ( DEBUG_DELAY );

    if ( c == '\n')
        break;

}

When I send "V1234" I get echoed back "v124". If I send "V123" I get "v123". It seems like I the uart code can only handle 4 characters? Is that right?

-Rich

January 19, 2011
by mrobbins
(NerdKits Staff)

mrobbins's Avatar

Hi Rich,

There shouldn't be anything special with 4 characters. Is it possible that your delay is causing some bytes to overwrite others?

As-is, the serial library doesn't do any buffering, so if one byte comes in while another one hasn't been "collected" yet by the uart_read call (or uart_getchar), then you might loes a byte. (It is possible to create buffered input using UART interrupts.)

Mike

January 19, 2011
by ramaral
ramaral's Avatar

Hi Mike,

That was it. I had assumed the data was buffered. I changed the code to read as fast as it can from the UART into a buffer, after which I process the buffered data. I did this crudely, without using interrupts. Can you point me to an example that uses UART interrupts to buffer incoming data? Thanks.

-Rich

January 20, 2011
by mrobbins
(NerdKits Staff)

mrobbins's Avatar

Hi Rich,

I thought that someone had provided an example of interrupt-based UARTs on the forums some months ago, but I'm having trouble finding it right now!

Mike

Post a Reply

Please log in to post a reply.

Did you know that interrupts can be used to trigger pieces of code when events happen? Learn more...