Reading the datasheet

Anything not related to STM32
Post Reply
dannyf
Posts: 447
Joined: Sat Jul 04, 2020 7:46 pm

Reading the datasheet

Post by dannyf »

I was given a couple chips to port some existing code from a quite similar chip from the same vendor to this target chip. With minimum changes, the code compiled without problem.

My typical set up is something like this, with the default internal rc oscillator:

Code: Select all

    //if enough time has elapsed
    if (ticks() - tick0 > LED_DLY) {			//if enough time has passed
        tick0 += LED_DLY;						//advance to the next match point
        pinFlip(LED);							//digitalWrite(LED, !digitalRead(LED));	//flip led, 105 ticks

        //measure timing
        tmp0=ticks();
        //put some tasks here
        tmp0=ticks() - tmp0;

        //display something on uart
        u2Print("F_CPU=                    ", F_CPU);	//89.9K polling, 9.3K interrupt
        u2Print("F_PHB=                    ", F_PHB);
        u2Print("ticks=                    ", ticks());
        u2Print("tmp0 =                    ", tmp0);
        u2Print("U2BRG=                    ", tmp0=U2BRG);
        u2Print("u2bps=                    ", u2bps());
        u2Println();
    }
and I'm getting garbage on the serial output. So obviously the baud rate is wrong. The equivalent of oscillator clock rate is about 10% off, on a chip that's spec'd to be 2% off (and my past experience with this vendor is that they are usually within 1% off, even for parts that are spec'd for +/- 10%.

So I thought maybe this particular chip is bad so I tried the code on the other chip. off by 10% and in the same direction. So either this vendor has gone downhill as of late (two chips have markings from 2021) or I struck gold :).

a couple days passed and I chanced upon an article about this chip family having an internal RC oscillator at 7.37Mhz - and my code came from a chip with an 8Mhz internal oscillator. :)

I have been at this for quite sometime now and I have always stressed the importance of reading the DS front to back. I should have taken up my own advice.

my embarrassment and your gain. :)
Post Reply

Return to “Off topic”