manual i2c id bit communication
This commit is contained in:
+23
-9
@@ -3,7 +3,6 @@
|
|||||||
* See LICENSE for details.
|
* See LICENSE for details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define F_CPU 16000000UL
|
|
||||||
#define BAUD 9600
|
#define BAUD 9600
|
||||||
|
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
@@ -11,6 +10,7 @@
|
|||||||
#include <util/setbaud.h>
|
#include <util/setbaud.h>
|
||||||
|
|
||||||
#include "bme280.h"
|
#include "bme280.h"
|
||||||
|
#include "i2c.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
@@ -35,8 +35,16 @@ void uart_putchar(char c) {
|
|||||||
UDR0 = c;
|
UDR0 = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void uart_putstr(const char *str) {
|
||||||
|
while(*str) {
|
||||||
|
uart_putchar(*str++);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
uart_init();
|
||||||
|
|
||||||
// make the LED pin an output for PORTB5
|
// make the LED pin an output for PORTB5
|
||||||
DDRB = 1 << 5;
|
DDRB = 1 << 5;
|
||||||
|
|
||||||
@@ -44,20 +52,26 @@ int main(void)
|
|||||||
float pressure = 0.0;
|
float pressure = 0.0;
|
||||||
float humidity = 0.0;
|
float humidity = 0.0;
|
||||||
|
|
||||||
bme280_init(0);
|
_delay_ms(500);
|
||||||
|
i2c_init();
|
||||||
|
i2c_start((0x76 << 1) | 0x00);
|
||||||
|
i2c_byte(0xD0);
|
||||||
|
i2c_stop();
|
||||||
|
|
||||||
temp = bme280_readTemperature(0);
|
_delay_us(10);
|
||||||
pressure = bme280_readPressure(0);
|
i2c_start((0x76 << 1) | 0x01);
|
||||||
humidity = bme280_readHumidity(0);
|
uint8_t ret = i2c_readAck();
|
||||||
|
i2c_stop();
|
||||||
|
|
||||||
|
if(ret == 0x60) { uart_putstr("\nbme280 detected.\n"); }
|
||||||
|
//temp = bme280_readTemperature(0);
|
||||||
|
//pressure = bme280_readPressure(0);
|
||||||
|
//humidity = bme280_readHumidity(0);
|
||||||
|
|
||||||
uart_init();
|
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
_delay_ms(1000);
|
_delay_ms(1000);
|
||||||
uart_putchar('!');
|
|
||||||
|
|
||||||
//printf("Temp: %f\tPressure: %f\tHumidity: %f\n", temp, pressure, humidity);
|
|
||||||
|
|
||||||
// toggle the LED
|
// toggle the LED
|
||||||
PORTB ^= 1 << 5;
|
PORTB ^= 1 << 5;
|
||||||
|
|||||||
Reference in New Issue
Block a user