2
\$\begingroup\$

I built this ATMega328PB circuit. schematics It runs at 3.3v from 1.5v battery using booster and 8MHz from external resonator (CSTCE8M00G52A-R0).

Using USBTinyISP I set fuses: Low-FF (for 8MHz), High-D8 (Boot Reset Vector Enabled), Ext-FD.

Using VisualStudio and vMicro plug-in I compiled a program for UNO. vMicro created a HEX file of my program WITH a bootloader which I uploaded over ISP and it runs well (blink the LED).

My final goal is to make a customized 8MHz bootloader but as intermediate steps I am trying to get a sign of life over serial using FT231X FTDI, and than upload a sketch over it.

I cut the 5v jumper on FT231X and connected 3.3v jumper instead. Then connected (without a battery):

ATmega328   FT321X
---------   ------
Vcc         Vcc 
GND         GND
GND         CTS
RST         DTR (over 0.1uF)
RxD         TX
TxD         RX

Since the default UNO bootloader UBRR register is set for 16MHz, I initialize it manually and try to push data over serial.

#define myubbr (8000000/16/9600-1)
void setup()
{
    pinMode(6, OUTPUT);
    // Init serial
    UBRR0H = (unsigned char)(myubbr >> 8);
    UBRR0L = (unsigned char)myubbr;
    UCSR0A = 0;//Disable U2X mode
    UCSR0B = (1 << TXEN0);//Enable transmitter
    UCSR0C = (3 << UCSZ00);//N81
}

void loop()
{
    digitalWrite(6, HIGH);
    delay(100);
    digitalWrite(6, LOW);
    delay(100);

    char * str = "Hello World";
    while (*str) {
        while (!(UCSR0A & (1 << UDRE0)));
        UDR0 = *str++; //send the data
    }
}

On the PC I run: avrdude -v -p m328p -c arduino -PCOM8 -b 9600 The port settings Avrdude recognizes the correct com port but gives:

avrdude: stk500_getsync(): not in sync: resp=0x00

The RX and TX LEDs on the FT231X never blink.

I don't even know if the problem is HW or SW. What am I doing wrong. What else can I try?

\$\endgroup\$
1
  • \$\begingroup\$ avrdude is for programming traffic, not for use with a sketch that prints out textual hello messages. You should test the USB serial by itself with a terminal program and installing/removing a loopback jumper. Also consider testing "normal" Arduino code on your board rather than your "original" direct register serial code. And if you do write custom code as you did with an GPIO output toggle embedded as you did, tell us if the GPIO did end up toggling or not, indicating that the program got stuck. \$\endgroup\$ Jun 15, 2018 at 14:37

2 Answers 2

1
\$\begingroup\$

In such a case, start with a working setup and then work your way step-by-step to your final setup. Like:

  • Start with 5V, 16 MHz, existing bootloader, Arduino IDE with 'hello world' sketch.
  • Change to 3.3V (lab supply) and 8 MHz. verify (baudrate will be halved)
  • use your FTDI-to-serial circuit. verify.
  • change to your 3.3V supply. verify.
  • change to using your IDE and ISP. verify.

If the step that causes things to beak is still to big, divide it into smaller steps. Divide and conquer! This is the same technique I use to find out what causes a compiler to crash on a 30k lines application. Takes some time, but you'll get there in the end.

\$\endgroup\$
4
  • \$\begingroup\$ Wouter, FOA thanks for your continued support for this project. On my board I cannot run 5v 16MHz, its hard wired to 3.3v at 8MHz. There is an component there that will burn at 5v and the resonator is 8MHz. So I don't understand the 1st step. \$\endgroup\$
    – Gary
    Apr 5, 2018 at 13:03
  • \$\begingroup\$ Don't limit yourself to 'your board'. Or (temporary) remove that component. \$\endgroup\$ Apr 5, 2018 at 19:31
  • 1
    \$\begingroup\$ There are existing 8 MHz bootloaders. Or your can use a 16 MHz build, you will just have to communicate with it at half the designed baud rate. \$\endgroup\$ Jun 15, 2018 at 14:38
  • \$\begingroup\$ @Chris Stratton - agreed. MCUDude's minicore allows to to choose the "channel" for the bootloader from UART0 and UART1. \$\endgroup\$
    – mckenzm
    Sep 20, 2019 at 3:45
1
\$\begingroup\$

Its working. It was ultimately a combination of switching between TX and RX and using half the baud rate of the bootloader on the PC. So first I loaded: setup { Serial.begin(9600); } loop { Serial.write("Hello"); }. hfuse=D9, opened Arduino Serial Monitor with baud rate 4800 and finally got printouts. Then I checked 115200 baud with 57600 on monitor in both TX and RX using read/write loop. Then I burned an UNO bootloader (default baud rate 115200) and set uno.upload.speed=57600 in boards.txt, set hfuse=D8 to run bootloader and now I can upload programs over serial.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.