• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Bad data on serial port

Kirby

Lifer
I've got a dev board sending out characters via serial to my pc (usb adapter) and i'm getting some bad data.

For example, I'm sending the character 'c' (0b01000011), but getting '£' (0b10100011). You can tell they're pretty close with just the first few bits off. I'm pretty sure the protocol settings are the same (baud = 9600, stop bit = 1, no parity and no flow control). This has worked before, and that's why it's frustrating.

Bad USB adapter?
 
When I see things like that it is usually because the wiring between the device and the input of the serial connector is too long or picking up interference.

Is it generating the same data every single time or is it corrupted randomly ?
 
if i send 'c', i get '£', with the occasional ã every 25 bytes or so.

tried another usb adapter, same thing. rs-232 is about 5 or 6 foot long, usb adapter is about a foot and a half.

another crazy thing is if i send 'C', i get 'Ã' really slow. like 4 times as slow. but i've know its transmitting the same speed on board.
 
Sounds to me like the sender's clock timing is off. Have you verified the pulse width of each bit sent? At 9600 bps, each bit should be 104.1 us. The more deviation from that figure, the more prone the error rate will be.


Also, make sure you have configured your UART properly.
 
if i send 'c', i get '£', with the occasional ã every 25 bytes or so.

tried another usb adapter, same thing. rs-232 is about 5 or 6 foot long, usb adapter is about a foot and a half.

another crazy thing is if i send 'C', i get 'Ã' really slow. like 4 times as slow. but i've know its transmitting the same speed on board.

Sounds like either the clocks are off or the baud rate is wrong somewhere. I see that when I use a device set for 57600 on a 9600 terminal.
 
I'm 99% sure my UART is correct. I haven't done anything with clock, it's whatever the default is.

I'm a noob at a scope, but each of the falling and rising edges is a multiple of 96 usecs, so I guess the baud is right.

One thing that is strange: in my main loop i check to make sure the transmit shirt reg is empty and the transmit buffer is not full. Then write a char to the uart transmit register, then pause and repeat. but when i look on the scope, i see main wiggle pattern, but there is some overlap to the left that happens a lot.
 
I cant help you but, I have to decide my career path in a month, so I have to ask you a question..
What do you have to do to work as a programmer for hardware stuff. like programming + electronics !!
Are you a electronics engineer or a computer engineer ?
 
You could try using a hamming code, barring that, a CRC32.

Another possibility is a unicode/ascii error is creeping up, make sure both sender and receiver are set to either unicode or ascii mode.
 
Last edited:
I cant help you but, I have to decide my career path in a month, so I have to ask you a question..
What do you have to do to work as a programmer for hardware stuff. like programming + electronics !!
Are you a electronics engineer or a computer engineer ?

If you want to build and program electronics components, I would recommend getting either a EE or a CE (though, most will say do a EE over a CE, I figure one is just a more specialized version of the other).

I wouldn't personally recommend studying electronics engineering. (someone can beat me if I'm wrong here) Electronics engineering is to Electrical engineering as CIT is to Computer Science. AFAIK Electronics engineering is like a neutered EE, they just give you parts so you can build things (without explaining exactly how the parts work).

If you really want to program, then I suggest going with a CS or Software engineering degree (Same thing?).
 
my university has a electrical and computing engineering that would be suited for the work i'm doing i think. sort of a mix between CS and EE.

i'm a junior in CS, and i've got a lot of knowledge gaps that's making this particular project difficult to me. i've had two classes that's done embedded work (both ECE), but this is making me pull my hair out.
 
I dont even know even half of those abbreviations .. WE just have ECE and CSE and EEE here in my country. They stand for Electronics and Communications, Computer science engineering, and electricals something.. There are many others, but not many universities offer them.
bullet.jpg
B.Tech. Computer Science & Engineering
bullet.jpg
B.Tech. Information Technology
bullet.jpg
B.Tech. Electronics & Communication Engineering
bullet.jpg
B.Tech. Electronics & Instrumentation Engineering
bullet.jpg
B.Tech. Electrical & Electronics Engineering
bullet.jpg
B.Tech. Civil Engineering
bullet.jpg
B.Tech. Mechanical Engineering
bullet.jpg
B.Tech. Industrial Engineering
bullet.jpg
B.Tech. BiotechnologyThese are what the university Iam going to join will be offering me. B.tech stands for Bachelor of technology, I guess its like BS(bachelor of science, not bull**) in US

Am mostly interested in both designing circuits and programming and doing both together. I guess I should stop Thread hijacking now.
 
Did you make the dev board?

if it has a normal level shifter (max232 or so) and you forget one of the caps it tends to do weird things like this 😉
Make sure you have the right crystal, and didn't set some divide-clock-by-x bit somewhere on accident...
 
I'm 99% sure my UART is correct. I haven't done anything with clock, it's whatever the default is.

I'm a noob at a scope, but each of the falling and rising edges is a multiple of 96 usecs, so I guess the baud is right.

One thing that is strange: in my main loop i check to make sure the transmit shirt reg is empty and the transmit buffer is not full. Then write a char to the uart transmit register, then pause and repeat. but when i look on the scope, i see main wiggle pattern, but there is some overlap to the left that happens a lot.


Well, there's your problem. At 96us,
 
I'm 99% sure my UART is correct. I haven't done anything with clock, it's whatever the default is.

I'm a noob at a scope, but each of the falling and rising edges is a multiple of 96 usecs, so I guess the baud is right.

One thing that is strange: in my main loop i check to make sure the transmit shirt reg is empty and the transmit buffer is not full. Then write a char to the uart transmit register, then pause and repeat. but when i look on the scope, i see main wiggle pattern, but there is some overlap to the left that happens a lot.


Well, there's your problem. At 96us, the MSB bit (which happens to be the one you're having issues with) will be off by ~40 us. Fix that timing issue and it will send correct data.
 
Well, it ended up that the baud wasn't right lol. I fixed my defined frequency and it's all good now. The flicker I was seeing was the scope, not from my chip.

With a PLL I've got it up to 26.7 MHz and 38400 baud. 😎
 
Back
Top