i2c对24c32进行读写

开发板环境:vivado 2017.1 ,开发板型号xc7z020clg400-1,这个工程主要是用i2c对24c32进行读写 

Step1 新建工程然后按照下面截图中进行配置(主要配置了DDR、i2c)

配置完成后进行综合、生成顶层文件,生成的顶层文件如下图所示

[csharp] view plain copy

  1.   

[html] view plain copy

  1. //Copyright 1986-2017 Xilinx, Inc. All Rights Reserved.  
  2. //--------------------------------------------------------------------------------  
  3. //Tool Version: Vivado v.2017.1 (win64) Build 1846317 Fri Apr 14 18:55:03 MDT 2017  
  4. //Date        : Sun Feb 18 22:06:05 2018  
  5. //Host        : MS-20180107KQQK running 64-bit Service Pack 1  (build 7601)  
  6. //Command     : generate_target design_1_wrapper.bd  
  7. //Design      : design_1_wrapper  
  8. //Purpose     : IP block netlist  
  9. //--------------------------------------------------------------------------------  
  10. `timescale 1 ps / 1 ps  
  11.   
  12. module design_1_wrapper  
  13.    (DDR_addr,  
  14.     DDR_ba,  
  15.     DDR_cas_n,  
  16.     DDR_ck_n,  
  17.     DDR_ck_p,  
  18.     DDR_cke,  
  19.     DDR_cs_n,  
  20.     DDR_dm,  
  21.     DDR_dq,  
  22.     DDR_dqs_n,  
  23.     DDR_dqs_p,  
  24.     DDR_odt,  
  25.     DDR_ras_n,  
  26.     DDR_reset_n,  
  27.     DDR_we_n,  
  28.     FIXED_IO_ddr_vrn,  
  29.     FIXED_IO_ddr_vrp,  
  30.     FIXED_IO_mio,  
  31.     FIXED_IO_ps_clk,  
  32.     FIXED_IO_ps_porb,  
  33.     FIXED_IO_ps_srstb,  
  34.     iic_0_scl_io,  
  35.     iic_0_sda_io);  
  36.   inout [14:0]DDR_addr;  
  37.   inout [2:0]DDR_ba;  
  38.   inout DDR_cas_n;  
  39.   inout DDR_ck_n;  
  40.   inout DDR_ck_p;  
  41.   inout DDR_cke;  
  42.   inout DDR_cs_n;  
  43.   inout [3:0]DDR_dm;  
  44.   inout [31:0]DDR_dq;  
  45.   inout [3:0]DDR_dqs_n;  
  46.   inout [3:0]DDR_dqs_p;  
  47.   inout DDR_odt;  
  48.   inout DDR_ras_n;  
  49.   inout DDR_reset_n;  
  50.   inout DDR_we_n;  
  51.   inout FIXED_IO_ddr_vrn;  
  52.   inout FIXED_IO_ddr_vrp;  
  53.   inout [53:0]FIXED_IO_mio;  
  54.   inout FIXED_IO_ps_clk;  
  55.   inout FIXED_IO_ps_porb;  
  56.   inout FIXED_IO_ps_srstb;  
  57.   inout iic_0_scl_io;  
  58.   inout iic_0_sda_io;  
  59.   
  60.   wire [14:0]DDR_addr;  
  61.   wire [2:0]DDR_ba;  
  62.   wire DDR_cas_n;  
  63.   wire DDR_ck_n;  
  64.   wire DDR_ck_p;  
  65.   wire DDR_cke;  
  66.   wire DDR_cs_n;  
  67.   wire [3:0]DDR_dm;  
  68.   wire [31:0]DDR_dq;  
  69.   wire [3:0]DDR_dqs_n;  
  70.   wire [3:0]DDR_dqs_p;  
  71.   wire DDR_odt;  
  72.   wire DDR_ras_n;  
  73.   wire DDR_reset_n;  
  74.   wire DDR_we_n;  
  75.   wire FIXED_IO_ddr_vrn;  
  76.   wire FIXED_IO_ddr_vrp;  
  77.   wire [53:0]FIXED_IO_mio;  
  78.   wire FIXED_IO_ps_clk;  
  79.   wire FIXED_IO_ps_porb;  
  80.   wire FIXED_IO_ps_srstb;  
  81.   wire iic_0_scl_i;  
  82.   wire iic_0_scl_io;  
  83.   wire iic_0_scl_o;  
  84.   wire iic_0_scl_t;  
  85.   wire iic_0_sda_i;  
  86.   wire iic_0_sda_io;  
  87.   wire iic_0_sda_o;  
  88.   wire iic_0_sda_t;  
  89.   
  90.   design_1 design_1_i  
  91.        (.DDR_addr(DDR_addr),  
  92.         .DDR_ba(DDR_ba),  
  93.         .DDR_cas_n(DDR_cas_n),  
  94.         .DDR_ck_n(DDR_ck_n),  
  95.         .DDR_ck_p(DDR_ck_p),  
  96.         .DDR_cke(DDR_cke),  
  97.         .DDR_cs_n(DDR_cs_n),  
  98.         .DDR_dm(DDR_dm),  
  99.         .DDR_dq(DDR_dq),  
  100.         .DDR_dqs_n(DDR_dqs_n),  
  101.         .DDR_dqs_p(DDR_dqs_p),  
  102.         .DDR_odt(DDR_odt),  
  103.         .DDR_ras_n(DDR_ras_n),  
  104.         .DDR_reset_n(DDR_reset_n),  
  105.         .DDR_we_n(DDR_we_n),  
  106.         .FIXED_IO_ddr_vrn(FIXED_IO_ddr_vrn),  
  107.         .FIXED_IO_ddr_vrp(FIXED_IO_ddr_vrp),  
  108.         .FIXED_IO_mio(FIXED_IO_mio),  
  109.         .FIXED_IO_ps_clk(FIXED_IO_ps_clk),  
  110.         .FIXED_IO_ps_porb(FIXED_IO_ps_porb),  
  111.         .FIXED_IO_ps_srstb(FIXED_IO_ps_srstb),  
  112.         .IIC_0_scl_i(iic_0_scl_i),  
  113.         .IIC_0_scl_o(iic_0_scl_o),  
  114.         .IIC_0_scl_t(iic_0_scl_t),  
  115.         .IIC_0_sda_i(iic_0_sda_i),  
  116.         .IIC_0_sda_o(iic_0_sda_o),  
  117.         .IIC_0_sda_t(iic_0_sda_t));  
  118.   IOBUF iic_0_scl_iobuf  
  119.        (.I(iic_0_scl_o),  
  120.         .IO(iic_0_scl_io),  
  121.         .O(iic_0_scl_i),  
  122.         .T(iic_0_scl_t));  
  123.   IOBUF iic_0_sda_iobuf  
  124.        (.I(iic_0_sda_o),  
  125.         .IO(iic_0_sda_io),  
  126.         .O(iic_0_sda_i),  
  127.         .T(iic_0_sda_t));  
  128. endmodule  

这个i2c工程的管脚是用emio引出的,所以要加这两个IOBUF,如果是mio引出的可以不加这两个IOBUF

[html] view plain copy

  1. IOBUF iic_0_scl_iobuf  

[html] view plain copy

  1. IOBUF iic_0_sda_iobuf  

Step2 新建一个xdc文件

[html] view plain copy

  1. set_property PACKAGE_PIN B19 [get_ports iic_0_sda_io]  
  2. set_property PACKAGE_PIN A20 [get_ports iic_0_scl_io]  
  3. set_property IOSTANDARD LVCMOS33 [get_ports iic_0_scl_io]  
  4. set_property IOSTANDARD LVCMOS33 [get_ports iic_0_sda_io]  
  5.   
  6. set_property PULLUP true [get_ports iic_0_scl_io]  
  7. set_property PULLUP true [get_ports iic_0_sda_io]  

新建的工程因为是emio引出的所以要分配管脚,如果mio就不用分配引脚。

这个xdc文件主要注意下面这两行,这两行主要是加内部上拉电阻

[html] view plain copy

  1. set_property PULLUP true [get_ports iic_0_scl_io]  
  2. set_property PULLUP true [get_ports iic_0_sda_io]  

Step3 生成bit文件

Step4点击菜单栏上的 File->Export->Export Hardware 导出硬件配置文件

Step5 打开SDK,然后新建一个fsbl

点击Next

点击Finish

Step 6  新建一个hello_world模板工程

新建完成后如下图所示

下面是hello_world的主程序这里是写入16位起始地址0x00进行连续写和读

[html] view plain copy

  1. /******************************************************************************  
  2. *  
  3. * Copyright (C) 2009 - 2014 Xilinx, Inc.  All rights reserved.  
  4. *  
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy  
  6. * of this software and associated documentation files (the "Software"), to deal  
  7. * in the Software without restriction, including without limitation the rights  
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell  
  9. * copies of the Software, and to permit persons to whom the Software is  
  10. * furnished to do so, subject to the following conditions:  
  11. *  
  12. * The above copyright notice and this permission notice shall be included in  
  13. * all copies or substantial portions of the Software.  
  14. *  
  15. * Use of the Software is limited solely to applications:  
  16. * (a) running on a Xilinx device, or  
  17. * (b) that interact with a Xilinx device through a bus or interconnect.  
  18. *  
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL  
  22. * XILINX  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,  
  23. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF  
  24. * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE  
  25. * SOFTWARE.  
  26. *  
  27. * Except as contained in this notice, the name of the Xilinx shall not be used  
  28. * in advertising or otherwise to promote the sale, use or other dealings in  
  29. * this Software without prior written authorization from Xilinx.  
  30. *  
  31. ******************************************************************************/  
  32.   
  33. /*  
  34.  * helloworld.c: simple test application  
  35.  *  
  36.  * This application configures UART 16550 to baud rate 9600.  
  37.  * PS7 UART (Zynq) is not initialized by this application, since  
  38.  * bootrom/bsp configures it to baud rate 115200  
  39.  *  
  40.  * ------------------------------------------------  
  41.  * | UART TYPE   BAUD RATE                        |  
  42.  * ------------------------------------------------  
  43.  *   uartns550   9600  
  44.  *   uartlite    Configurable only in HW design  
  45.  *   ps7_uart    115200 (configured by bootrom/bsp)  
  46.  */  
  47.   
  48. #include <stdio.h>  
  49. #include "platform.h"  
  50. #include "xil_printf.h"  
  51.   
  52.   
  53. #include "sleep.h"  
  54. #include "xiicps.h"  
  55.   
  56. XIicPs IicInstance;     /* The instance of the IIC device. */  
  57.   
  58. #define IIC_DEVICE_ID   XPAR_XIICPS_0_DEVICE_ID  
  59.   
  60. u8 WriteBuffer[2 + 1];  
  61.   
  62. u8 ReadBuffer[1];   /* Read buffer for reading a page. */  
  63.   
  64. struct sensor_register {  
  65.     u8 value;  
  66. };  
  67.   
  68.   
  69. static const struct sensor_register i2c_data[] = {  
  70.   
  71.     { 0x00},  
  72.     { 0x00},  
  73.     { 0x04},  
  74.     { 0x01},  
  75.     { 0x11},  
  76.     { 0x02},  
  77.     { 0x3a},  
  78.     { 0x70},  
  79.     { 0x17},  
  80.     { 0x98},  
  81.     { 0x08},  
  82.     { 0x65},  
  83.     { 0x04},  
  84.     { 0x70},  
  85.     { 0x01},  
  86.   
  87.     { 0xff},/* over */  
  88. };  
  89.   
  90.   
  91.   
  92. int iic_master_init(void)  
  93. {  
  94.     int Status;  
  95.     XIicPs_Config *ConfigPtr;   /* Pointer to configuration data */  
  96.   
  97.     ConfigPtr = XIicPs_LookupConfig(IIC_DEVICE_ID);  
  98.     if (ConfigPtr == NULL) {  
  99.         return XST_FAILURE;  
  100.     }  
  101.   
  102.     Status = XIicPs_CfgInitialize(&IicInstance, ConfigPtr,  
  103.                     ConfigPtr->BaseAddress);  
  104.     if (Status != XST_SUCCESS) {  
  105.         return XST_FAILURE;  
  106.     }  
  107.   
  108.     XIicPs_SetSClk(&IicInstance, 400000);  
  109.   
  110.     return XST_SUCCESS;  
  111. }  
  112.   
  113.   
  114.   
  115. int iic_write_read_8(u8 Device_Address,u8 First_Word_Address,u8 Second_Word_address,u8 data)  
  116. {  
  117.     int Status;  
  118.   
  119.     WriteBuffer[0]  =   First_Word_Address;  
  120.     WriteBuffer[1]  =   Second_Word_address;  
  121.     WriteBuffer[2]  =   data;  
  122.   
  123.     Status = XIicPs_MasterSendPolled(&IicInstance, WriteBuffer,  
  124.                       3, Device_Address>>1);  
  125.     if (Status != XST_SUCCESS) {  
  126.         return XST_FAILURE;  
  127.     }  
  128.   
  129.     while (XIicPs_BusIsBusy(&IicInstance));  
  130.   
  131.     usleep(2500);  
  132.     if (Status != XST_SUCCESS) {  
  133.         return XST_FAILURE;  
  134.     }  
  135.   
  136.     WriteBuffer[0]  =   First_Word_Address;  
  137.     WriteBuffer[1]  =   Second_Word_address;  
  138.   
  139.     Status = XIicPs_MasterSendPolled(&IicInstance, WriteBuffer,  
  140.                       2, Device_Address>>1);  
  141.     if (Status != XST_SUCCESS) {  
  142.         return XST_FAILURE;  
  143.     }  
  144.   
  145.     while (XIicPs_BusIsBusy(&IicInstance));  
  146.   
  147.     usleep(2500);  
  148.   
  149.     Status = XIicPs_MasterRecvPolled(&IicInstance, ReadBuffer,  
  150.                       1, Device_Address>>1);  
  151.     if (Status != XST_SUCCESS) {  
  152.         return XST_FAILURE;  
  153.     }  
  154.     while (XIicPs_BusIsBusy(&IicInstance));  
  155.     xil_printf("0x%02x\r\n",ReadBuffer[0]);  
  156.     return 0;  
  157. }  
  158.   
  159.   
  160. int main(void)  
  161. {  
  162.     int     i;  
  163.     u8     Device_Address;  
  164.     u8     First_Word_Address;  
  165.     u8     Second_Word_address;  
  166.   
  167.   
  168.     Device_Address      = 0xAE;  
  169.     First_Word_Address  = 0x00;  
  170.     Second_Word_address = 0x00;  
  171.     i = 0;  
  172.   
  173.   
  174.   
  175. iic_master_init();  
  176.   
  177.   
  178. while(1)  
  179. {  
  180.     if(i2c_data[i].value==0xff)  
  181.         break;  
  182.     iic_write_read_8(Device_Address,First_Word_Address,Second_Word_address,i2c_data[i].value);  
  183.     i++;  
  184. }  
  185.   
  186.   
  187.     return 0;  
  188. }  

[html] view plain copy

  1.   

这两个i2c的读写程序都比较简单,这里只是简单的介绍下要注意的地方

这个主要是对master控制器进行初始化

[html] view plain copy

  1. iic_master_init();  

初始化中主要主要注意:

[html] view plain copy

  1. ConfigPtr = XIicPs_LookupConfig(IIC_DEVICE_ID);  

其中这个i2c的设备ID主要是看你用zynq哪个设备,一般都是用的i2c0、i2c1

XPAR_XIICPS_0_DEVICE_ID  //对应i2c0

XPAR_XIICPS_1_DEVICE_ID //对应i2c1

下面的这段代码主要设置i2c的工作频率,我这里用的是400k

[html] view plain copy

  1. XIicPs_SetSClk(&IicInstance, 400000);  

初始化完成后主要就是进行读写了,在读写之前要将进行的读写的数据进行缓冲,所以会用到Buffer

这个24c32的地址是16位,数据是8位,所以一共要用到3个Buffer进行缓冲

[html] view plain copy

  1. WriteBuffer[0]  =   First_Word_Address;  
  2. WriteBuffer[1]  =   Second_Word_address;  
  3. WriteBuffer[2]  =   data;  

上面的是写的3个缓冲Buffer,这个是读的缓冲Buffer只有一个

[html] view plain copy

  1. ReadBuffer[0]  

缓冲Buffer做完后就开始进行写,这里进行写的函数只要设置缓冲Buffer的个数以及所接的24C32的设备地址就可以了

[html] view plain copy

  1. Status = XIicPs_MasterSendPolled(&IicInstance, WriteBuffer,  
  2.                   3, Device_Address>>1);  

当数据写完成后开始进行读,读分为两步:第一步写入你所要读的地址、第二步读这个地址里的数据

[html] view plain copy

  1. 1.    Status = XIicPs_MasterSendPolled(&IicInstance, WriteBuffer,  
  2.                       2, Device_Address>>1);  

[html] view plain copy

  1. 2.   Status = XIicPs_MasterRecvPolled(&IicInstance, ReadBuffer,  
  2.                       1, Device_Address>>1);  

这里是连续读写,所以开始写入16位的0x00的起始地址,然后对这个起始地址不断累加进行连续读

对特定地址进行读写和连续读写差不多,这里不再进行介绍

最后的这个是打印i2c读Buffer里的数据

[html] view plain copy

  1. xil_printf("0x%02x\r\n",ReadBuffer[0]);  

 

 

 

 

 

开发板环境:vivado 2017.1 ,开发板型号xc7z020clg400-1,这个工程主要用I2C接口读取STLM75的温度,

同时也会对其它的相关寄存器进行读写以验证程序的正确性。

下面的这个截图是STLM75的一些管脚介绍:

下面的截图是z-turn开发板上STLM75的硬件连接情况,可以看出这个STLM75的设备地址是  1001001×(最后一位是读写控制位)

Step1  新建vivado 工程后,调用zynq核并配置,这里主要配置了DDR、I2C

Step2 新建一个xdc文件

[html] view plain copy

  1. set_property PACKAGE_PIN P15 [get_ports iic_0_sda_io]    
  2. set_property PACKAGE_PIN P16 [get_ports iic_0_scl_io]    
  3. set_property IOSTANDARD LVCMOS33 [get_ports iic_0_scl_io]    
  4. set_property IOSTANDARD LVCMOS33 [get_ports iic_0_sda_io]    
  5.     
  6. set_property PULLUP true [get_ports iic_0_scl_io]    
  7. set_property PULLUP true [get_ports iic_0_sda_io]   

这个STLM75是接在PL端所以用的emio来进行I2C的读写

Step3 进行综合、生成顶层文件,顶层文件如下所示(注意I2C一定要加下面的IOBUF)

[html] view plain copy

  1. //Copyright 1986-2017 Xilinx, Inc. All Rights Reserved.  
  2. //--------------------------------------------------------------------------------  
  3. //Tool Version: Vivado v.2017.1 (win64) Build 1846317 Fri Apr 14 18:55:03 MDT 2017  
  4. //Date        : Mon Feb 26 18:28:07 2018  
  5. //Host        : taowei running 64-bit Service Pack 1  (build 7601)  
  6. //Command     : generate_target design_1_wrapper.bd  
  7. //Design      : design_1_wrapper  
  8. //Purpose     : IP block netlist  
  9. //--------------------------------------------------------------------------------  
  10. `timescale 1 ps / 1 ps  
  11.   
  12. module design_1_wrapper  
  13.    (DDR_addr,  
  14.     DDR_ba,  
  15.     DDR_cas_n,  
  16.     DDR_ck_n,  
  17.     DDR_ck_p,  
  18.     DDR_cke,  
  19.     DDR_cs_n,  
  20.     DDR_dm,  
  21.     DDR_dq,  
  22.     DDR_dqs_n,  
  23.     DDR_dqs_p,  
  24.     DDR_odt,  
  25.     DDR_ras_n,  
  26.     DDR_reset_n,  
  27.     DDR_we_n,  
  28.     FIXED_IO_ddr_vrn,  
  29.     FIXED_IO_ddr_vrp,  
  30.     FIXED_IO_mio,  
  31.     FIXED_IO_ps_clk,  
  32.     FIXED_IO_ps_porb,  
  33.     FIXED_IO_ps_srstb,  
  34.     iic_0_scl_io,  
  35.     iic_0_sda_io);  
  36.   inout [14:0]DDR_addr;  
  37.   inout [2:0]DDR_ba;  
  38.   inout DDR_cas_n;  
  39.   inout DDR_ck_n;  
  40.   inout DDR_ck_p;  
  41.   inout DDR_cke;  
  42.   inout DDR_cs_n;  
  43.   inout [3:0]DDR_dm;  
  44.   inout [31:0]DDR_dq;  
  45.   inout [3:0]DDR_dqs_n;  
  46.   inout [3:0]DDR_dqs_p;  
  47.   inout DDR_odt;  
  48.   inout DDR_ras_n;  
  49.   inout DDR_reset_n;  
  50.   inout DDR_we_n;  
  51.   inout FIXED_IO_ddr_vrn;  
  52.   inout FIXED_IO_ddr_vrp;  
  53.   inout [53:0]FIXED_IO_mio;  
  54.   inout FIXED_IO_ps_clk;  
  55.   inout FIXED_IO_ps_porb;  
  56.   inout FIXED_IO_ps_srstb;  
  57.   inout iic_0_scl_io;  
  58.   inout iic_0_sda_io;  
  59.   
  60.   wire [14:0]DDR_addr;  
  61.   wire [2:0]DDR_ba;  
  62.   wire DDR_cas_n;  
  63.   wire DDR_ck_n;  
  64.   wire DDR_ck_p;  
  65.   wire DDR_cke;  
  66.   wire DDR_cs_n;  
  67.   wire [3:0]DDR_dm;  
  68.   wire [31:0]DDR_dq;  
  69.   wire [3:0]DDR_dqs_n;  
  70.   wire [3:0]DDR_dqs_p;  
  71.   wire DDR_odt;  
  72.   wire DDR_ras_n;  
  73.   wire DDR_reset_n;  
  74.   wire DDR_we_n;  
  75.   wire FIXED_IO_ddr_vrn;  
  76.   wire FIXED_IO_ddr_vrp;  
  77.   wire [53:0]FIXED_IO_mio;  
  78.   wire FIXED_IO_ps_clk;  
  79.   wire FIXED_IO_ps_porb;  
  80.   wire FIXED_IO_ps_srstb;  
  81.   wire iic_0_scl_i;  
  82.   wire iic_0_scl_io;  
  83.   wire iic_0_scl_o;  
  84.   wire iic_0_scl_t;  
  85.   wire iic_0_sda_i;  
  86.   wire iic_0_sda_io;  
  87.   wire iic_0_sda_o;  
  88.   wire iic_0_sda_t;  
  89.   
  90.   design_1 design_1_i  
  91.        (.DDR_addr(DDR_addr),  
  92.         .DDR_ba(DDR_ba),  
  93.         .DDR_cas_n(DDR_cas_n),  
  94.         .DDR_ck_n(DDR_ck_n),  
  95.         .DDR_ck_p(DDR_ck_p),  
  96.         .DDR_cke(DDR_cke),  
  97.         .DDR_cs_n(DDR_cs_n),  
  98.         .DDR_dm(DDR_dm),  
  99.         .DDR_dq(DDR_dq),  
  100.         .DDR_dqs_n(DDR_dqs_n),  
  101.         .DDR_dqs_p(DDR_dqs_p),  
  102.         .DDR_odt(DDR_odt),  
  103.         .DDR_ras_n(DDR_ras_n),  
  104.         .DDR_reset_n(DDR_reset_n),  
  105.         .DDR_we_n(DDR_we_n),  
  106.         .FIXED_IO_ddr_vrn(FIXED_IO_ddr_vrn),  
  107.         .FIXED_IO_ddr_vrp(FIXED_IO_ddr_vrp),  
  108.         .FIXED_IO_mio(FIXED_IO_mio),  
  109.         .FIXED_IO_ps_clk(FIXED_IO_ps_clk),  
  110.         .FIXED_IO_ps_porb(FIXED_IO_ps_porb),  
  111.         .FIXED_IO_ps_srstb(FIXED_IO_ps_srstb),  
  112.         .IIC_0_scl_i(iic_0_scl_i),  
  113.         .IIC_0_scl_o(iic_0_scl_o),  
  114.         .IIC_0_scl_t(iic_0_scl_t),  
  115.         .IIC_0_sda_i(iic_0_sda_i),  
  116.         .IIC_0_sda_o(iic_0_sda_o),  
  117.         .IIC_0_sda_t(iic_0_sda_t));  
  118.   IOBUF iic_0_scl_iobuf  
  119.        (.I(iic_0_scl_o),  
  120.         .IO(iic_0_scl_io),  
  121.         .O(iic_0_scl_i),  
  122.         .T(iic_0_scl_t));  
  123.   IOBUF iic_0_sda_iobuf  
  124.        (.I(iic_0_sda_o),  
  125.         .IO(iic_0_sda_io),  
  126.         .O(iic_0_sda_i),  
  127.         .T(iic_0_sda_t));  
  128. endmodule  

Step4 生成bit文件

 

Step5 点击菜单栏上的 File->Export->Export Hardware 导出硬件配置文件

Step 5 打开SDK,然后新建一个fsbl

Step 6 新建一个hello_world模板工程

工程新建完成后,我们看手册可以看到这个STLM75一个有4个寄存器

当指针寄存器值不同时可以对不同的寄存器进行操作,当然这个指针寄存器上电后的初始状态是处在温度寄存器,指针寄存器数值:

00 可以对温度寄存器进行读(Temperature register)

01 可以对配置寄存器进行读写(Configuration register)

10 可以对滞后寄存器进行读写(Hysteresis register)

11 可以对超温阈值寄存器进行读写(Overtemperature shutdown)

对这个指针寄存器进行写的波形图如下所示

这个D0和D1分别对应手册上的P0和P1,只要对指针寄存器写入不同的值就可以对上面四个寄存器进行访问

这个对指针寄存器进行写的过程中要注意这个D2~D7要都为0,D0和D1可以是00、01、10、11中的一个就行

我这里先对配置寄存器进行读,下面是hello_world工程的主程序

[html] view plain copy

  1. /******************************************************************************  
  2. *  
  3. * Copyright (C) 2009 - 2014 Xilinx, Inc.  All rights reserved.  
  4. *  
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy  
  6. * of this software and associated documentation files (the "Software"), to deal  
  7. * in the Software without restriction, including without limitation the rights  
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell  
  9. * copies of the Software, and to permit persons to whom the Software is  
  10. * furnished to do so, subject to the following conditions:  
  11. *  
  12. * The above copyright notice and this permission notice shall be included in  
  13. * all copies or substantial portions of the Software.  
  14. *  
  15. * Use of the Software is limited solely to applications:  
  16. * (a) running on a Xilinx device, or  
  17. * (b) that interact with a Xilinx device through a bus or interconnect.  
  18. *  
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL  
  22. * XILINX  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,  
  23. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF  
  24. * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE  
  25. * SOFTWARE.  
  26. *  
  27. * Except as contained in this notice, the name of the Xilinx shall not be used  
  28. * in advertising or otherwise to promote the sale, use or other dealings in  
  29. * this Software without prior written authorization from Xilinx.  
  30. *  
  31. ******************************************************************************/  
  32.   
  33. /*  
  34.  * helloworld.c: simple test application  
  35.  *  
  36.  * This application configures UART 16550 to baud rate 9600.  
  37.  * PS7 UART (Zynq) is not initialized by this application, since  
  38.  * bootrom/bsp configures it to baud rate 115200  
  39.  *  
  40.  * ------------------------------------------------  
  41.  * | UART TYPE   BAUD RATE                        |  
  42.  * ------------------------------------------------  
  43.  *   uartns550   9600  
  44.  *   uartlite    Configurable only in HW design  
  45.  *   ps7_uart    115200 (configured by bootrom/bsp)  
  46.  */  
  47.   
  48. #include <stdio.h>  
  49. #include "platform.h"  
  50. #include "xil_printf.h"  
  51.   
  52.   
  53. #include "sleep.h"  
  54. #include "xiicps.h"  
  55.   
  56. XIicPs IicInstance;     /* The instance of the IIC device. */  
  57.   
  58. #define IIC_DEVICE_ID   XPAR_XIICPS_0_DEVICE_ID  
  59.   
  60. u8 WriteBuffer[1];  
  61.   
  62. u16 ReadBuffer[1];   /* Read buffer for reading a page. */  
  63.   
  64.   
  65.   
  66.   
  67. int iic_master_init(void)  
  68. {  
  69.     int Status;  
  70.     XIicPs_Config *ConfigPtr;   /* Pointer to configuration data */  
  71.   
  72.     ConfigPtr = XIicPs_LookupConfig(IIC_DEVICE_ID);  
  73.     if (ConfigPtr == NULL) {  
  74.         return XST_FAILURE;  
  75.     }  
  76.   
  77.     Status = XIicPs_CfgInitialize(&IicInstance, ConfigPtr,  
  78.                     ConfigPtr->BaseAddress);  
  79.     if (Status != XST_SUCCESS) {  
  80.         return XST_FAILURE;  
  81.     }  
  82.   
  83.     XIicPs_SetSClk(&IicInstance, 400000);  
  84.   
  85.     return XST_SUCCESS;  
  86. }  
  87.   
  88.   
  89.   
  90. int iic_write_read_8(u8 Device_Address,u8 Pointer_Address)  
  91. {  
  92.     int Status;  
  93.   
  94.     WriteBuffer[0]  =   Pointer_Address; //0x01  
  95.   
  96.   
  97.     Status = XIicPs_MasterSendPolled(&IicInstance, WriteBuffer,  
  98.                       1, Device_Address>>1);  
  99.     if (Status != XST_SUCCESS) {  
  100.         return XST_FAILURE;  
  101.     }  
  102.   
  103.     while (XIicPs_BusIsBusy(&IicInstance));  
  104.   
  105.     usleep(2500);  
  106.     if (Status != XST_SUCCESS) {  
  107.         return XST_FAILURE;  
  108.     }  
  109.   
  110.   
  111.   
  112.     Status = XIicPs_MasterRecvPolled(&IicInstance, ReadBuffer,  
  113.                       1, Device_Address>>1);  
  114.     if (Status != XST_SUCCESS) {  
  115.         return XST_FAILURE;  
  116.     }  
  117.     while (XIicPs_BusIsBusy(&IicInstance));  
  118.     xil_printf("0x%04x\r\n",ReadBuffer[0]);  
  119.     return 0;  
  120. }  
  121.   
  122.   
  123. int main(void)  
  124. {  
  125.   
  126.     u8 Device_Address;  
  127.   
  128.     Device_Address = 0x93; //10010011  
  129.   
  130.   
  131. iic_master_init();  
  132.   
  133.   
  134. while(1)  
  135.  {  
  136.   
  137.     iic_write_read_8(Device_Address,0x01);  
  138.     sleep(1);  
  139.  }  
  140.   
  141.   
  142.     return 0;  
  143. }  

下面是打印的寄存器的值

可以看到和手册里的一致

接下来是对滞后寄存器进行读,下面是hello_world工程的主程序

[html] view plain copy

  1. /******************************************************************************  
  2. *  
  3. * Copyright (C) 2009 - 2014 Xilinx, Inc.  All rights reserved.  
  4. *  
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy  
  6. * of this software and associated documentation files (the "Software"), to deal  
  7. * in the Software without restriction, including without limitation the rights  
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell  
  9. * copies of the Software, and to permit persons to whom the Software is  
  10. * furnished to do so, subject to the following conditions:  
  11. *  
  12. * The above copyright notice and this permission notice shall be included in  
  13. * all copies or substantial portions of the Software.  
  14. *  
  15. * Use of the Software is limited solely to applications:  
  16. * (a) running on a Xilinx device, or  
  17. * (b) that interact with a Xilinx device through a bus or interconnect.  
  18. *  
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL  
  22. * XILINX  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,  
  23. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF  
  24. * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE  
  25. * SOFTWARE.  
  26. *  
  27. * Except as contained in this notice, the name of the Xilinx shall not be used  
  28. * in advertising or otherwise to promote the sale, use or other dealings in  
  29. * this Software without prior written authorization from Xilinx.  
  30. *  
  31. ******************************************************************************/  
  32.   
  33. /*  
  34.  * helloworld.c: simple test application  
  35.  *  
  36.  * This application configures UART 16550 to baud rate 9600.  
  37.  * PS7 UART (Zynq) is not initialized by this application, since  
  38.  * bootrom/bsp configures it to baud rate 115200  
  39.  *  
  40.  * ------------------------------------------------  
  41.  * | UART TYPE   BAUD RATE                        |  
  42.  * ------------------------------------------------  
  43.  *   uartns550   9600  
  44.  *   uartlite    Configurable only in HW design  
  45.  *   ps7_uart    115200 (configured by bootrom/bsp)  
  46.  */  
  47.   
  48. #include <stdio.h>  
  49. #include "platform.h"  
  50. #include "xil_printf.h"  
  51.   
  52.   
  53. #include "sleep.h"  
  54. #include "xiicps.h"  
  55.   
  56. XIicPs IicInstance;     /* The instance of the IIC device. */  
  57.   
  58. #define IIC_DEVICE_ID   XPAR_XIICPS_0_DEVICE_ID  
  59.   
  60. u8 WriteBuffer[1];  
  61.   
  62. u16 ReadBuffer[1];   /* Read buffer for reading a page. */  
  63.   
  64.   
  65.   
  66.   
  67. int iic_master_init(void)  
  68. {  
  69.     int Status;  
  70.     XIicPs_Config *ConfigPtr;   /* Pointer to configuration data */  
  71.   
  72.     ConfigPtr = XIicPs_LookupConfig(IIC_DEVICE_ID);  
  73.     if (ConfigPtr == NULL) {  
  74.         return XST_FAILURE;  
  75.     }  
  76.   
  77.     Status = XIicPs_CfgInitialize(&IicInstance, ConfigPtr,  
  78.                     ConfigPtr->BaseAddress);  
  79.     if (Status != XST_SUCCESS) {  
  80.         return XST_FAILURE;  
  81.     }  
  82.   
  83.     XIicPs_SetSClk(&IicInstance, 400000);  
  84.   
  85.     return XST_SUCCESS;  
  86. }  
  87.   
  88.   
  89.   
  90. int iic_write_read_8(u8 Device_Address,u8 Pointer_Address)  
  91. {  
  92.     int Status;  
  93.   
  94.     WriteBuffer[0]  =   Pointer_Address; //0x02  
  95.   
  96.   
  97.     Status = XIicPs_MasterSendPolled(&IicInstance, WriteBuffer,  
  98.                       1, Device_Address>>1);  
  99.     if (Status != XST_SUCCESS) {  
  100.         return XST_FAILURE;  
  101.     }  
  102.   
  103.     while (XIicPs_BusIsBusy(&IicInstance));  
  104.   
  105.     usleep(2500);  
  106.     if (Status != XST_SUCCESS) {  
  107.         return XST_FAILURE;  
  108.     }  
  109.   
  110.   
  111.   
  112.     Status = XIicPs_MasterRecvPolled(&IicInstance, ReadBuffer,  
  113.                       1, Device_Address>>1);  
  114.     if (Status != XST_SUCCESS) {  
  115.         return XST_FAILURE;  
  116.     }  
  117.     while (XIicPs_BusIsBusy(&IicInstance));  
  118.     xil_printf("0x%04x\r\n",ReadBuffer[0]);  
  119.     return 0;  
  120. }  
  121.   
  122.   
  123. int main(void)  
  124. {  
  125.   
  126.     u8 Device_Address;  
  127.   
  128.     Device_Address = 0x93; //10010011  
  129.   
  130.   
  131. iic_master_init();  
  132.   
  133.   
  134. while(1)  
  135.  {  
  136.   
  137.     iic_write_read_8(Device_Address,0x02);  
  138.     sleep(1);  
  139.  }  
  140.   
  141.   
  142.     return 0;  
  143. }  

下面是打印的寄存器的值

可以看到和手册里的一致

再对超温阈值寄存器进行读,下面是hello_world工程的主程序

[html] view plain copy

  1. /******************************************************************************  
  2. *  
  3. * Copyright (C) 2009 - 2014 Xilinx, Inc.  All rights reserved.  
  4. *  
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy  
  6. * of this software and associated documentation files (the "Software"), to deal  
  7. * in the Software without restriction, including without limitation the rights  
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell  
  9. * copies of the Software, and to permit persons to whom the Software is  
  10. * furnished to do so, subject to the following conditions:  
  11. *  
  12. * The above copyright notice and this permission notice shall be included in  
  13. * all copies or substantial portions of the Software.  
  14. *  
  15. * Use of the Software is limited solely to applications:  
  16. * (a) running on a Xilinx device, or  
  17. * (b) that interact with a Xilinx device through a bus or interconnect.  
  18. *  
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL  
  22. * XILINX  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,  
  23. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF  
  24. * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE  
  25. * SOFTWARE.  
  26. *  
  27. * Except as contained in this notice, the name of the Xilinx shall not be used  
  28. * in advertising or otherwise to promote the sale, use or other dealings in  
  29. * this Software without prior written authorization from Xilinx.  
  30. *  
  31. ******************************************************************************/  
  32.   
  33. /*  
  34.  * helloworld.c: simple test application  
  35.  *  
  36.  * This application configures UART 16550 to baud rate 9600.  
  37.  * PS7 UART (Zynq) is not initialized by this application, since  
  38.  * bootrom/bsp configures it to baud rate 115200  
  39.  *  
  40.  * ------------------------------------------------  
  41.  * | UART TYPE   BAUD RATE                        |  
  42.  * ------------------------------------------------  
  43.  *   uartns550   9600  
  44.  *   uartlite    Configurable only in HW design  
  45.  *   ps7_uart    115200 (configured by bootrom/bsp)  
  46.  */  
  47.   
  48. #include <stdio.h>  
  49. #include "platform.h"  
  50. #include "xil_printf.h"  
  51.   
  52.   
  53. #include "sleep.h"  
  54. #include "xiicps.h"  
  55.   
  56. XIicPs IicInstance;     /* The instance of the IIC device. */  
  57.   
  58. #define IIC_DEVICE_ID   XPAR_XIICPS_0_DEVICE_ID  
  59.   
  60. u8 WriteBuffer[1];  
  61.   
  62. u16 ReadBuffer[1];   /* Read buffer for reading a page. */  
  63.   
  64.   
  65.   
  66.   
  67. int iic_master_init(void)  
  68. {  
  69.     int Status;  
  70.     XIicPs_Config *ConfigPtr;   /* Pointer to configuration data */  
  71.   
  72.     ConfigPtr = XIicPs_LookupConfig(IIC_DEVICE_ID);  
  73.     if (ConfigPtr == NULL) {  
  74.         return XST_FAILURE;  
  75.     }  
  76.   
  77.     Status = XIicPs_CfgInitialize(&IicInstance, ConfigPtr,  
  78.                     ConfigPtr->BaseAddress);  
  79.     if (Status != XST_SUCCESS) {  
  80.         return XST_FAILURE;  
  81.     }  
  82.   
  83.     XIicPs_SetSClk(&IicInstance, 400000);  
  84.   
  85.     return XST_SUCCESS;  
  86. }  
  87.   
  88.   
  89.   
  90. int iic_write_read_8(u8 Device_Address,u8 Pointer_Address)  
  91. {  
  92.     int Status;  
  93.   
  94.     WriteBuffer[0]  =   Pointer_Address; //0x03  
  95.   
  96.   
  97.     Status = XIicPs_MasterSendPolled(&IicInstance, WriteBuffer,  
  98.                       1, Device_Address>>1);  
  99.     if (Status != XST_SUCCESS) {  
  100.         return XST_FAILURE;  
  101.     }  
  102.   
  103.     while (XIicPs_BusIsBusy(&IicInstance));  
  104.   
  105.     usleep(2500);  
  106.     if (Status != XST_SUCCESS) {  
  107.         return XST_FAILURE;  
  108.     }  
  109.   
  110.   
  111.   
  112.     Status = XIicPs_MasterRecvPolled(&IicInstance, ReadBuffer,  
  113.                       1, Device_Address>>1);  
  114.     if (Status != XST_SUCCESS) {  
  115.         return XST_FAILURE;  
  116.     }  
  117.     while (XIicPs_BusIsBusy(&IicInstance));  
  118.     xil_printf("0x%04x\r\n",ReadBuffer[0]);  
  119.     return 0;  
  120. }  
  121.   
  122.   
  123. int main(void)  
  124. {  
  125.   
  126.     u8 Device_Address;  
  127.   
  128.     Device_Address = 0x93; //10010011  
  129.   
  130.   
  131. iic_master_init();  
  132.   
  133.   
  134. while(1)  
  135.  {  
  136.   
  137.     iic_write_read_8(Device_Address,0x03);  
  138.     sleep(1);  
  139.  }  
  140.   
  141.   
  142.     return 0;  
  143. }  

下面是打印的寄存器的值

可以看到和手册里的一致

从上面可以看出对前面的几个寄存器进行读出的数据和手册一样说明,这个I2C读写是正确的,

最后对温度寄存器进行读,下面是hello_world工程的主程序

[html] view plain copy

  1. /******************************************************************************  
  2. *  
  3. * Copyright (C) 2009 - 2014 Xilinx, Inc.  All rights reserved.  
  4. *  
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy  
  6. * of this software and associated documentation files (the "Software"), to deal  
  7. * in the Software without restriction, including without limitation the rights  
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell  
  9. * copies of the Software, and to permit persons to whom the Software is  
  10. * furnished to do so, subject to the following conditions:  
  11. *  
  12. * The above copyright notice and this permission notice shall be included in  
  13. * all copies or substantial portions of the Software.  
  14. *  
  15. * Use of the Software is limited solely to applications:  
  16. * (a) running on a Xilinx device, or  
  17. * (b) that interact with a Xilinx device through a bus or interconnect.  
  18. *  
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL  
  22. * XILINX  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,  
  23. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF  
  24. * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE  
  25. * SOFTWARE.  
  26. *  
  27. * Except as contained in this notice, the name of the Xilinx shall not be used  
  28. * in advertising or otherwise to promote the sale, use or other dealings in  
  29. * this Software without prior written authorization from Xilinx.  
  30. *  
  31. ******************************************************************************/  
  32.   
  33. /*  
  34.  * helloworld.c: simple test application  
  35.  *  
  36.  * This application configures UART 16550 to baud rate 9600.  
  37.  * PS7 UART (Zynq) is not initialized by this application, since  
  38.  * bootrom/bsp configures it to baud rate 115200  
  39.  *  
  40.  * ------------------------------------------------  
  41.  * | UART TYPE   BAUD RATE                        |  
  42.  * ------------------------------------------------  
  43.  *   uartns550   9600  
  44.  *   uartlite    Configurable only in HW design  
  45.  *   ps7_uart    115200 (configured by bootrom/bsp)  
  46.  */  
  47.   
  48. #include <stdio.h>  
  49. #include "platform.h"  
  50. #include "xil_printf.h"  
  51.   
  52.   
  53. #include "sleep.h"  
  54. #include "xiicps.h"  
  55.   
  56. XIicPs IicInstance;     /* The instance of the IIC device. */  
  57.   
  58. #define IIC_DEVICE_ID   XPAR_XIICPS_0_DEVICE_ID  
  59.   
  60. u8 WriteBuffer[1];  
  61.   
  62. u16 ReadBuffer[1];   /* Read buffer for reading a page. */  
  63.   
  64.   
  65.   
  66.   
  67. int iic_master_init(void)  
  68. {  
  69.     int Status;  
  70.     XIicPs_Config *ConfigPtr;   /* Pointer to configuration data */  
  71.   
  72.     ConfigPtr = XIicPs_LookupConfig(IIC_DEVICE_ID);  
  73.     if (ConfigPtr == NULL) {  
  74.         return XST_FAILURE;  
  75.     }  
  76.   
  77.     Status = XIicPs_CfgInitialize(&IicInstance, ConfigPtr,  
  78.                     ConfigPtr->BaseAddress);  
  79.     if (Status != XST_SUCCESS) {  
  80.         return XST_FAILURE;  
  81.     }  
  82.   
  83.     XIicPs_SetSClk(&IicInstance, 400000);  
  84.   
  85.     return XST_SUCCESS;  
  86. }  
  87.   
  88.   
  89.   
  90. int iic_write_read_8(u8 Device_Address,u8 Pointer_Address)  
  91. {  
  92.     int Status;  
  93.   
  94.     WriteBuffer[0]  =   Pointer_Address; //0x00  
  95.   
  96.   
  97.     Status = XIicPs_MasterSendPolled(&IicInstance, WriteBuffer,  
  98.                       1, Device_Address>>1);  
  99.     if (Status != XST_SUCCESS) {  
  100.         return XST_FAILURE;  
  101.     }  
  102.   
  103.     while (XIicPs_BusIsBusy(&IicInstance));  
  104.   
  105.     usleep(2500);  
  106.     if (Status != XST_SUCCESS) {  
  107.         return XST_FAILURE;  
  108.     }  
  109.   
  110.   
  111.   
  112.     Status = XIicPs_MasterRecvPolled(&IicInstance, ReadBuffer,  
  113.                       1, Device_Address>>1);  
  114.     if (Status != XST_SUCCESS) {  
  115.         return XST_FAILURE;  
  116.     }  
  117.     while (XIicPs_BusIsBusy(&IicInstance));  
  118.     xil_printf("0x%04x\r\n",ReadBuffer[0]);  
  119.     return 0;  
  120. }  
  121.   
  122.   
  123. int main(void)  
  124. {  
  125.   
  126.     u8 Device_Address;  
  127.   
  128.     Device_Address = 0x93; //10010011  
  129.   
  130.   
  131. iic_master_init();  
  132.   
  133.   
  134. while(1)  
  135.  {  
  136.   
  137.     iic_write_read_8(Device_Address,0x00);  
  138.     sleep(1);  
  139.  }  
  140.   
  141.   
  142.     return 0;  
  143. }  

下面是打印的寄存器的值

今天天气预报差不多是11度左右,将0x0019十六进制数化为10进制是25再除2差不多是12.5度这是在屋内所以差不多

之后我将手放到STLM75上可以看到温度从0x0019上升到0x001A说明温度是在上升的。

我们再看这个温度寄存器0x0019的最高位是0所以温度是一个正的温度

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值