Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and the Yahoo Answers website is now in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Are UART, SPI, I2C implementations microcontroller dependent?

Is it possible to create one file, say for example uart.c to be generic, so that I can call the uart functions for different microcontrollers, say for example avr and arm? or is it a must that for every microcontroller I will have to create the the uart functions from scratch?

1 Answer

Relevance
  • 2 weeks ago

    It's technically possible, if you have a header file with enough #ifdef sections to define the addresses and bits for every different MCU, and probably a few in the C file as well to cover major implementation differences.

    It cannot be done with a simple fixed file that has no controlling defines or variables to select the hardware.

    You could just keep adding every new, separate, UART routine set to the same file, with an #ifdef around each for that CPU type.

    Eventually you would have a file that worked on all the MCUs you use.

Still have questions? Get your answers by asking now.