0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線(xiàn)課程
  • 觀看技術(shù)視頻
  • 寫(xiě)文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

求一種基于Infineon的信息采集系統(tǒng)設(shè)計(jì)方案

冬至子 ? 來(lái)源:xinshuwei ? 作者:xinshuwei ? 2023-07-19 15:22 ? 次閱讀

項(xiàng)目簡(jiǎn)介

此次項(xiàng)目主要是基于PSOC6 英飛凌 PSoC?62 with CAPSENSE? evaluation kit 實(shí)現(xiàn)OLED 顯示溫度、氣壓室內(nèi)信息。

整體框架如下:

1.jpg

1.通過(guò)板載的dap 和uart 進(jìn)行串口log 打印及程序刷寫(xiě)
2.通過(guò)I2C 進(jìn)行BMP280 的驅(qū)動(dòng)
3.通過(guò)I2C 進(jìn)行oled SSD1306的顯示

實(shí)現(xiàn)步驟

1.rtt 中添加 軟件包

使能sensor 驅(qū)動(dòng) iic 驅(qū)動(dòng) uart驅(qū)動(dòng)

2.默認(rèn)的bmp280 包不能使用,由于使用最新的rt版本 不兼容,進(jìn)行驅(qū)動(dòng)層修改

#ifndef SENSOR_BS_BMP280_H__
#define SENSOR_BS_BMP280_H__
#include "drivers/sensor.h"
#include "bmp280.h"
#define BMP280_ADDR_DEFAULT BMP280_I2C_ADDR_SEC
#define BMP280_I2CBUS_NAME "i2c1"
int rt_hw_bmp280_init(const char *name, struct rt_sensor_config *cfg);
#endif
定義I2C bus名稱(chēng)
定義BMP280 默認(rèn)地址
硬件初始化

static struct rt_sensor_ops sensor_ops =
{
_bmp280_fetch_data,
_bmp280_control
};
int rt_hw_bmp280_init(const char *name, struct rt_sensor_config *cfg)
{
int result;
rt_sensor_t sensor_pres = RT_NULL, sensor_temp = RT_NULL;
result = _rt_bmp280_init(&cfg->intf);
if (result != RT_EOK)
{
LOG_E("_rt_bmp280_init err code: %d", result);
return -RT_ERROR;
}
else
{
sensor_pres = rt_calloc(1, sizeof(struct rt_sensor_device));
if (sensor_pres == RT_NULL)
{
LOG_E("rt_calloc error");
return -RT_ERROR;
}
sensor_pres->info.type = RT_SENSOR_TYPE_BARO;
sensor_pres->info.vendor = RT_SENSOR_VENDOR_BOSCH;
sensor_pres->info.name = "bmp280_pres";
sensor_pres->info.unit = RT_SENSOR_UNIT_PA;
sensor_pres->info.intf_type = RT_SENSOR_INTF_I2C;
sensor_pres->info.scale.range_max = SENSOR_PRES_RANGE_MAX;
sensor_pres->info.scale.range_min = SENSOR_PRES_RANGE_MIN;
//sensor_pres->info.period_min = 0;
rt_memcpy(&sensor_pres->config, cfg, sizeof(struct rt_sensor_config));
sensor_pres->ops = &sensor_ops;
result = rt_hw_sensor_register(sensor_pres, name, RT_DEVICE_FLAG_RDWR, (void *)RT_NULL);
if (result != RT_EOK)
{
LOG_E("device register err code: %d", result);
goto __exit;
}
sensor_temp = rt_calloc(1, sizeof(struct rt_sensor_device));
if (sensor_temp == RT_NULL)
{
LOG_E("rt_calloc error");
goto __exit;
}
sensor_temp->info.type = RT_SENSOR_TYPE_TEMP;
sensor_temp->info.vendor = RT_SENSOR_VENDOR_BOSCH;
sensor_temp->info.name = "bmp280_temp";
sensor_temp->info.unit = RT_SENSOR_UNIT_CELSIUS;
sensor_temp->info.intf_type = RT_SENSOR_INTF_I2C;
sensor_temp->info.scale.range_max = SENSOR_TEMP_RANGE_MAX;
sensor_temp->info.scale.range_min = SENSOR_TEMP_RANGE_MIN;
//sensor_temp->info.period_min = 0;
rt_memcpy(&sensor_temp->config, cfg, sizeof(struct rt_sensor_config));
sensor_temp->ops = &sensor_ops;
result = rt_hw_sensor_register(sensor_temp, name, RT_DEVICE_FLAG_RDWR, RT_NULL);
if (result != RT_EOK)
{
LOG_E("device register err code: %d", result);
goto __exit;
}
}
LOG_I("bmp280_sensor init success");
return RT_EOK;
__exit:
if (sensor_pres)
rt_free(sensor_pres);
if (sensor_temp)
rt_free(sensor_temp);
return -RT_ERROR;
}
rt_sensor_info 結(jié)構(gòu)體改變了很多,需要根據(jù)sensor 驅(qū)動(dòng)進(jìn)行相應(yīng)的修改
設(shè)置 bmp 280 更新速度

static rt_err_t _bmp280_set_odr(rt_sensor_t sensor, rt_uint32_t args)
{
int8_t rslt;
struct bmp280_config conf;
if(args==1||args==2||args==4||args==8||args==16||args==2048||args==BMP280_ODR_2000_MS||args==BMP280_ODR_4000_MS)
{
rslt = bmp280_get_config(&conf, &bmp);
if(rslt!=BMP280_OK)
{
print_rslt(" bmp280_get_config status", rslt);
return -RT_ERROR;
}
switch(args)
{
case 1 : conf.odr = BMP280_ODR_1000_MS; break;
case 2 : conf.odr = BMP280_ODR_500_MS; break;
case 4 : conf.odr = BMP280_ODR_250_MS; break;
case 8 : conf.odr = BMP280_ODR_125_MS; break;
case 16 : conf.odr = BMP280_ODR_62_5_MS; break;
case 2048 : conf.odr = BMP280_ODR_0_5_MS; break;
case BMP280_ODR_2000_MS : conf.odr = BMP280_ODR_2000_MS; break;
case BMP280_ODR_4000_MS : conf.odr = BMP280_ODR_4000_MS; break;
default: return -RT_ERROR;
}
rslt = bmp280_set_config(&conf, &bmp);
if(rslt!=BMP280_OK)
{
print_rslt(" bmp280_set_config status", rslt);
return -RT_ERROR;
}
return RT_EOK;
}
else
{
// LOG_E("only 1,2,4,8,16,2048,BMP280_ODR_2000_MS,BMP280_ODR_4000_MS could set");
return -RT_ERROR;
}
}
最新版本的sensor control 去掉了好多控制,做了相應(yīng)的注釋

static rt_err_t _bmp280_control(struct rt_sensor_device *sensor, int cmd, void *args)
{
rt_err_t result = RT_EOK;
switch (cmd)
{
case RT_SENSOR_CTRL_GET_ID:
result = _bmp280_get_id(sensor,args);
break;
#if 0
case RT_SENSOR_CTRL_SET_RANGE:
result = -RT_ERROR;
break;
case RT_SENSOR_CTRL_SET_ODR:
result = _bmp280_set_odr(sensor,(rt_uint32_t)args & 0xffff);
break;
case RT_SENSOR_CTRL_SET_MODE:
break;
case RT_SENSOR_CTRL_SET_POWER:
result = _bmp280_set_POWER(sensor,(rt_uint32_t)args & 0xff);
break;
#endif
case RT_SENSOR_CTRL_SELF_TEST:
result = -RT_ERROR;
break;
default:
// LOG_E("only RT_SENSOR_CTRL_GET_ID,RT_SENSOR_CTRL_SET_POWER,RT_SENSOR_CTRL_SET_ODR could set");
return -RT_ERROR;
}
return result;
}
3.bmp280 app 初始化

#include
#include
#include
#include "sensor_bs_bmp280.h"
#define BMP_NAME "bmp280"
int bmp280_port(void)
{
struct rt_sensor_config cfg;
cfg.intf.dev_name = BMP280_I2CBUS_NAME;
rt_hw_bmp280_init("bmp280", &cfg);
return 0;
}
INIT_APP_EXPORT(bmp280_port);

1.jpg

上電log 打印可以看到device 已經(jīng)注冊(cè)成功

4.oled 顯示驅(qū)動(dòng)

oled 顯示通過(guò)u8g2進(jìn)行驅(qū)動(dòng),這里參考ssd1306 I2C 初始化過(guò)程 代碼如下:

u8g2_t u8g2;
// Initialization
u8g2_Setup_ssd1306_i2c_128x64_noname_f( &u8g2, U8G2_R0, u8x8_byte_sw_i2c, u8x8_gpio_and_delay_rtthread);
u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_I2C_CLOCK, OLED_I2C_PIN_SCL);
u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_I2C_DATA, OLED_I2C_PIN_SDA);

顯示初始化前 ,先尋找驅(qū)動(dòng)

rt_device_t temp_dev =RT_NULL;
  rt_device_t baro_dev =RT_NULL;
  rt_size_t res =0;
  temp_dev = rt_device_find(BMP_TEMP);
  if(temp_dev == RT_NULL)
  {
      rt_kprintf("can not find bmp280 tempn");
      return ;
  }
  baro_dev = rt_device_find(BMP_BARO);
  if(temp_dev == RT_NULL)
  {
      rt_kprintf("can not find bmp280 baron");
      return ;
  }
  if (rt_device_open(temp_dev, RT_DEVICE_FLAG_RDWR) != RT_EOK) {
      rt_kprintf("open device failed!n");
      return;
  }
  if (rt_device_open(baro_dev, RT_DEVICE_FLAG_RDWR) != RT_EOK) {
      rt_kprintf("open device failed!n");
      return;
  }

然后顯示線(xiàn)程的主循環(huán)中按一定的間隔進(jìn)行sensor 數(shù)據(jù)讀取,然后更新顯示到oled 上

res = rt_device_read(temp_dev, 0, &temp_data, 1);
      if (res != 1) {
          rt_kprintf("read data failed!size is %dn", res);
          rt_device_close(temp_dev);
          return;
      }
      res = rt_device_read(baro_dev, 0, &baro_data, 1);
      if (res != 1) {
          rt_kprintf("read data failed!size is %dn", res);
          rt_device_close(baro_dev);
          return;
      }
      u8g2_ClearBuffer(&u8g2);
      u8g2_DrawStr(&u8g2, 12, 12, "psoc6 demo");
      temp_int =temp_data.data.temp;
      //sprintf(buf,"temp:%.2f C",temp_data.data.temp);
      sprintf(buf,"temp:%d.%d C",temp_int /10,temp_int %10);
      u8g2_DrawStr(&u8g2, 32, 40, buf);
      sprintf(buf,"baro:%.0fPa",baro_data.data.baro );
      u8g2_DrawStr(&u8g2, 32, 56, buf);
      u8g2_SendBuffer(&u8g2);
      rt_thread_mdelay(100);
聲明:本文內(nèi)容及配圖由入駐作者撰寫(xiě)或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場(chǎng)。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問(wèn)題,請(qǐng)聯(lián)系本站處理。 舉報(bào)投訴
  • I2C總線(xiàn)
    +關(guān)注

    關(guān)注

    8

    文章

    386

    瀏覽量

    60791
  • OLED顯示
    +關(guān)注

    關(guān)注

    1

    文章

    55

    瀏覽量

    16980
  • SSD1306
    +關(guān)注

    關(guān)注

    3

    文章

    40

    瀏覽量

    13577
  • BMP280
    +關(guān)注

    關(guān)注

    1

    文章

    20

    瀏覽量

    5701
  • RTThread
    +關(guān)注

    關(guān)注

    7

    文章

    132

    瀏覽量

    40776
收藏 人收藏

    評(píng)論

    相關(guān)推薦

    分享一種不錯(cuò)的基于FPGA和USB的通用CCD采集系統(tǒng)設(shè)計(jì)方案

    提出一種基于FPGA和USB的通用CCD采集系統(tǒng)設(shè)計(jì)方案。該系統(tǒng)在不改變硬件的情況下可以采集多種
    發(fā)表于 04-22 06:23

    大神分享一種PPSM嵌入式RTOS中的窗口系統(tǒng)設(shè)計(jì)方案

    大神分享一種PPSM嵌入式RTOS中的窗口系統(tǒng)設(shè)計(jì)方案
    發(fā)表于 04-27 06:20

    一種多通道同步數(shù)據(jù)采集及壓縮系統(tǒng)設(shè)計(jì)方案  

    一種多通道同步數(shù)據(jù)采集及壓縮系統(tǒng)設(shè)計(jì)方案?! ?/div>
    發(fā)表于 04-28 06:13

    一種多路模擬數(shù)字采集與處理系統(tǒng)設(shè)計(jì)方案

    一種多路模擬數(shù)字采集與處理系統(tǒng)設(shè)計(jì)方案
    發(fā)表于 04-28 07:04

    一種新型系統(tǒng)級(jí)可編程芯片的設(shè)計(jì)方案

    一種新型系統(tǒng)級(jí)可編程芯片的設(shè)計(jì)方案
    發(fā)表于 05-06 07:44

    一種直流固態(tài)功控系統(tǒng)設(shè)計(jì)方案

    一種基于CPLD控制的直流固態(tài)功控系統(tǒng)設(shè)計(jì)方案
    發(fā)表于 05-06 06:23

    一種智能電源模塊測(cè)試系統(tǒng)設(shè)計(jì)方案

    一種智能電源模塊測(cè)試系統(tǒng)設(shè)計(jì)方案
    發(fā)表于 05-10 06:35

    一種遠(yuǎn)程智能垃圾桶報(bào)警系統(tǒng)設(shè)計(jì)方案

    一種遠(yuǎn)程智能垃圾桶報(bào)警系統(tǒng)設(shè)計(jì)方案
    發(fā)表于 05-19 07:10

    一種智能物品清點(diǎn)系統(tǒng)設(shè)計(jì)方案

    一種智能物品清點(diǎn)系統(tǒng)設(shè)計(jì)方案
    發(fā)表于 05-20 07:29

    一種視頻檢測(cè)和遠(yuǎn)程控制的嵌入式系統(tǒng)設(shè)計(jì)方案

    一種視頻檢測(cè)和遠(yuǎn)程控制的嵌入式系統(tǒng)設(shè)計(jì)方案
    發(fā)表于 05-27 06:38

    大佬分享一種小型通信系統(tǒng)設(shè)計(jì)方案

    大佬分享一種小型通信系統(tǒng)設(shè)計(jì)方案
    發(fā)表于 05-28 06:13

    大佬分享一種多光譜可見(jiàn)光遙感圖像壓縮系統(tǒng)設(shè)計(jì)方案

    大佬分享一種多光譜可見(jiàn)光遙感圖像壓縮系統(tǒng)設(shè)計(jì)方案
    發(fā)表于 06-02 06:39

    一種陶瓷揚(yáng)聲器系統(tǒng)的放大器設(shè)計(jì)方案

    一種陶瓷揚(yáng)聲器系統(tǒng)的放大器設(shè)計(jì)方案
    發(fā)表于 06-04 07:10

    一種基于ARM的視頻監(jiān)控系統(tǒng)設(shè)計(jì)方案

    本文介紹了一種基于ARM的視頻監(jiān)控系統(tǒng)設(shè)計(jì)方案,采用軟壓縮算法,討論了系統(tǒng)的硬件和軟件設(shè)計(jì)。
    發(fā)表于 06-08 06:27

    一種基于單片機(jī)的簡(jiǎn)易洗衣機(jī)系統(tǒng)仿真設(shè)計(jì)方案

    一種基于單片機(jī)的簡(jiǎn)易洗衣機(jī)系統(tǒng)仿真設(shè)計(jì)方案
    發(fā)表于 01-17 08:09