Just at the outset to say thank you for reading this, it is a bit long, but it's because of context.
I have a fair bit of programming background, some in arduino ( In Arduino I wrote some control stuff for stepper motors and an interrupt driven shaft encoder), so that's roughly my level. For various reasons I thought I'd dip into 'direct' programming (using a mega4809 because it has the four USARTs), so I bought a nice book which I'm following. I've called it 'direct' programming, because in my head it would be 'non Arduino'. So whilst I'm following the concepts of setting bits in various registers to configure the avr peripherals and I'm ok with bit shifting and logical operations, I've come unstuck, perhaps in a concepts way, here's my problem:
Thinking about the USART chapter in the book, we've got to writing code for transmitChar and receiveChar and it's good to do this because you learn how stuff works. However, I'm thinking this is of course reusable code, so I'd want it in a library, but then I'm thinking why reinvent the wheel - this stuff must be in a library aklready? So this is where I'm stuck, I think there must be a usart library? If there is one, where would that be and how would I find out what functions it has?
The other question related to reusability of code is (I think), Arduino. I know Arduino has libraries and Arduino works with atmega4809, so should I be using Arduino libraries or (MegaCoreX is it the same thing)?
So if I use Aduino libraries my code is of the form Setup() and loop() rather than Main() is that right? and does this matter?
You can see I'm at a pretty basic level when it comes to avr, many thanks for help on this,