Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Device drivers in mc

Status
Not open for further replies.

Madbunny1

Member level 2
Joined
May 22, 2017
Messages
49
Helped
1
Reputation
2
Reaction score
1
Trophy points
8
Activity points
380
Hi,

What are the device drivers mean in microcontrollers? Can anyone give examples?

Thanks
 

An example of driver for LM75 temperature sensor:
Code:
#include "LM75.h"

char LM75_PowerOn (LM75_StructTypeDef * LM75_Struct, LM75_PowerTypeDef Enable)
{
	return LM75_Struct->WriteReg(LM75_Struct->I2C_Adrs, LM75_ConfigReg, Enable & 1);
}

char LM75_GetResult (LM75_StructTypeDef * LM75_Struct)
{
	static char result;
	static signed char tmp[2];
	
	result = LM75_Struct->ReadReg(LM75_Struct->I2C_Adrs, LM75_TempReg, (char*)tmp, sizeof(tmp));
	LM75_Struct->T = (float)(tmp[0]);
	if (tmp[1] & 0x80) LM75_Struct->T += 0.5;
	
	return result;
}
It have to be connected to SPI driver to be used. For RTOS purpose, SPI driver have to use mutex.
To use driver you need to connect SPI to LM75 driver by assigning functions in configuration structure:
Code:
typedef struct
{
	/* Variables */
	float T;
	char I2C_Adrs;
	
	/* Functions */
[B]	char (*WriteReg)(char I2C_Adrs, char Reg, char Value);
	char (*ReadReg) (char I2C_Adrs, char Reg, char * buf, char size);[/B]
	
}LM75_StructTypeDef;
If the are only one instance of device can be used, I normally using static declaration. But any amount of LM75 sensors can be used in this example.
For example, you create a driver like that:
Code:
LM75_StructTypeDef * LM75_Driver = malloc(sizeof(*LM75_Driver));
Than you fullfill the structure:
Code:
LM75_Driver -> I2C_Adrs = 0x90;
LM75_Driver -> WriteReg = LM75_SPI_Write;
LM75_Driver -> ReadReg = LM75_SPI_Read;

Than you init the sensor:
Code:
if (LM75_PowerOn (LM75_Driver, ENABLE)) //error, sensor not exist, kill driver
free(LM75_Driver);

Or use it while it needed.
 
thank you easyrider,

Why do we have to write device Drivers for the microcontroller when the manufacturer of microcontroller already provided device Drivers(.h and .c files except our application c file) for the Controller?
 

You can continue use someone other's drivers in your development, but don't be supprised that it doesn't work as you wanna to.
 

Firmware vs software

Hi,

Can we say firmware is also known as device drivers? And if no, what exactly does it mean?
 
Last edited by a moderator:

No, firmware is the resident program running on the microcontroller, whereas device drivers are distinct parts of the code designed to handle specific physical devices of the board or even built in on the chip itselt.
 

No, firmware is the resident program running on the microcontroller, whereas device drivers are distinct parts of the code designed to handle specific physical devices of the board or even built in on the chip itselt.
Do you mean allocating memory such as ROM, EPROM, setting micro controller clock frequency are called as Firmware?

Thanks
 

You're making things confusing, let's ease:
The code you program in uC is called firmware, whatever it does.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top