MPL115A1 SPI Digital Barometer connected to ATMEGA16

Your source for all things Atmel.

Moderator: phalanx

Post Reply
Posts: 2
Joined: Wed Nov 20, 2013 1:54 am

MPL115A1 SPI Digital Barometer connected to ATMEGA16

Post by pavi017 » Sun Nov 24, 2013 7:50 am

Code: Select all

#define Waitfor1(register, BIT) while(!(register & (1<<BIT)));
#define Waitfor0(register, BIT) while((register & (1<<BIT)));
void mastermode()
DDRB = DDRB | ob10110000; \\ this sets the sck mosi and ss as outputs
DDRB = DDRB & ob10111111; \\ this sets miso as output
SPCR |=(1<<MSTR); \\ set as master
SPCR | = (1<<SPR0)|(1<<SPR1); \\ clock divided by 128
SPCR | = (1<<SPE);
char RecieveByte()
{   Waitfor1(SPSR, SPIF);
    return SPDR;

 Void SendByte (char byte, int slavenumber)
{   PORTB = PORTB & ob1110111;
    SPDR = byte;
    Waitfor1(SPSR, SPIF);
I have written these initializations
If you check the data sheet of the sensor you find that there is a MSB and LSB for both temp and pressure readings.
Using the code i have how can i retrieve these values so i can combine them into one 16 bit value. The code am asking is for the atmega16 where port b pin 5 6 7 are the spi connections and pin 4 will be the slave select which will be connected to the sensor.
pic of the spi readings of the sensor

Post Reply