2016-12-06 26 views
0

我正在使用Silicon Laboratories BGM121藍牙低功耗模塊和SLWSTK6101C入門工具包。該套件是一個RHT傳感器(Si7021),它連接到板上的i2c並通過它連接到模塊。SLWSTK6101C上帶有板載Si7021的I2C通信BGM121(BGScript)

隨着示例項目我直接閃過,沒有通過Simplicity Studio v4編譯,它工作正常,我得到了適當的價值。

問題:我必須使用SiLabs BGScript語言對模塊進行編程。我不能用C做,因爲GCC目前還不支持,我沒有IAR許可證。

我想讀出傳感器數據(溫度)並希望通過BLE將其發送到Android應用程序。 BLE部分不是問題,我構建了他們在bluetooth.org上採用的服務中描述的服務/特性。我試圖使用SiLabs的BGScript示例來測試它是否可行。但是,即使製造商提供的官方SDK BGScript示例也不起作用。

這裏是我的配置,我的代碼:

<!-- I2C configuration --> 
<!-- Settings: SCL pin is PC11 and SDA pin is PC10 --> 
<i2c scl_pin="PC11" sda_pin="PC10"/> 

的I2C通信代碼:

export dim i2c_result 
export dim i2c_len 
export dim i2c_buffer(4) 
export dim temperature(5) 
export dim timeout 
export dim data 
dim result 

const sensor_slave_addr = $40 

export procedure sensorRead() 

    call led1_on() 


    call hardware_write_i2c(0,sensor_slave_addr,1,$f3) 

    i2c_result = 1 
    timeout = 0 
    while (i2c_result != 0) && (timeout < 50) 
     call hardware_read_i2c(0,sensor_slave_addr,2)(i2c_result,i2c_len,i2c_buffer(0:i2c_len)) 
     timeout = timeout + 1 
     if i2c_result = 0 then 
      call led1_off() 
     end if 
    end while 

    call hardware_stop_i2c(0) 

    if(timeout < 50) then 
     # Check that the I2C was read properly and the while loop didn't 
     # end because of the timeout. 
     # Measurement from the I2C read is in big endian format and must be 
     # converted to little-endian by swapping bytes. 
     data = i2c_buffer(0:1) << 8 | i2c_buffer(1:1) 
     #call led1_off() 
    else 
     data = $25 
    end if 


    #Flags field -> 0: °C , 1: °F 
    temperature(0:1)=$00 
    temperature(1:4)=float(data*1757/65536-469, -1) 



    call gatt_server_write_attribute_value(temperature_char, 0, 5, temperature(0:5))(result) 
    call gatt_server_send_characteristic_notification($FF, temperature_char, 5, temperature(0:5))(result) 

    end 

到LED程序的調用是隻是爲了測試,如果它開始/結束I2C通信。

我發現我從來沒有在「i2c_result」上獲得成功。所以它沒有得到傳感器的值。但我看不出爲什麼。

任何想法?

提前致謝!

回答

0

它已經解決了。 SiLabs的支持給了我一個暗示,他們幾天前發佈了新的SDK v2.1。在這個更新的SDK中有工作項目。

但是,您可以使用工作傳感器運行舊項目。

BGM121不像其他電路板那樣爲傳感器提供固定電源。您必須將「電源引腳」設置爲邏輯1,以便爲傳感器供電。其他模塊已將傳感器靜態鏈接到邏輯1.

它通過在hardware.xml文件中設置附加的GPIO來完成。

<gpio port="D" pin="9" mode="pushpull" out="1" /> 

或者通過調用程序將其設定爲

call hardware_configure_gpio(3, 9, hardware_gpio_mode_push_pull, 1) 

這一切都解決了。現在可以使用傳感器。