想做一个简单的 微电容位移传感器  采用AD7150 来获得电容值

AD7150 是I2C传送数据,因为想做的简单,就用MSP430G2553单片机做主控,模拟I2C通信方式,来获取输入

程式语言部分该如何编码?

底下是我参考open source

msp430g2xx3_uscib0_i2c_12.c

进行修改

但不了解各个状态要如何设定 (寄存器位址等)?

请各位大大协助

#include

#include "msp430g2553.h"

#define NUM_BYTES_TX 1                         // How many bytes?

#define NUM_BYTES_RX 1

int RXByteCtr, RPT_Flag = 0;                // enables repeated start when 1

volatile unsigned char RxBuffer[128];       // Allocate 128 byte of RAM

unsigned char *PTxData;                     // Pointer to TX data

unsigned char *PRxData;                     // Pointer to RX data

unsigned char TXByteCtr, RX = 0;

unsigned char MSData = 0x55;

unsigned int RxWord;

unsigned int RxByteCtr;

unsigned char i;

float        pFdata;

float        chRange;

void Setup_TX(void);

void Setup_RX(void);

void Transmit(void);

void Receive(void);

float AD7150_Cap(void);

void main(void)

{

WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

P1SEL |= BIT6 + BIT7;                     // Assign I2C pins to USCI_B0

P1SEL2|= BIT6 + BIT7;                     // Assign I2C pins to USCI_B0

while(1){

//Transmit process

Setup_TX();

RPT_Flag = 1;

Transmit();

while (UCB0CTL1 & UCTXSTP);             // Ensure stop condition got sent

//Receive process

Setup_RX();

Receive();

while (UCB0CTL1 & UCTXSTP);             // Ensure stop condition got sent

}

}

//-------------------------------------------------------------------------------

// The USCI_B0 data ISR is used to move received data from the I2C slave

// to the MSP430 memory. It is structured such that it can be used to receive

// any 2+ number of bytes by pre-loading RXByteCtr with the byte count.

//-------------------------------------------------------------------------------

#pragma vector = USCIAB0TX_VECTOR

__interrupt void USCIAB0TX_ISR(void)

{

if(RX == 1){                              // Master Recieve?

RXByteCtr--;                              // Decrement RX byte counter

if (RXByteCtr)

{

*PRxData++ = UCB0RXBUF;                 // Move RX data to address PRxData

}

else

{

if(RPT_Flag == 0)

UCB0CTL1 |= UCTXSTP;                // No Repeated Start: stop condition

if(RPT_Flag == 1){                    // if Repeated Start: do nothing

RPT_Flag = 0;

}

*PRxData = UCB0RXBUF;                   // Move final RX data to PRxData

__bic_SR_register_on_exit(CPUOFF);      // Exit LPM0

}}

else{                                     // Master Transmit

if (TXByteCtr)                        // Check TX byte counter

{

UCB0TXBUF = MSData++;                   // Load TX buffer

TXByteCtr--;                            // Decrement TX byte counter

}

else

{

if(RPT_Flag == 1){

RPT_Flag = 0;

PTxData = &MSData;                      // TX array start address

TXByteCtr = NUM_BYTES_TX;                  // Load TX byte counter

__bic_SR_register_on_exit(CPUOFF);

}

else{

UCB0CTL1 |= UCTXSTP;                    // I2C stop condition

IFG2 &= ~UCB0TXIFG;                     // Clear USCI_B0 TX int flag

__bic_SR_register_on_exit(CPUOFF);      // Exit LPM0

}

}

}

}

void Setup_TX(void){

_DINT();

RX = 0;

IE2 &= ~UCB0RXIE;

while (UCB0CTL1 & UCTXSTP);               // Ensure stop condition got sent// Disable RX interrupt

UCB0CTL1 |= UCSWRST;                      // Enable SW reset

UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC;     // I2C Master, synchronous mode

UCB0CTL1 = UCSSEL_2 + UCSWRST;            // Use SMCLK, keep SW reset

UCB0BR0 = 12;                             // fSCL = SMCLK/12 = ~100kHz

UCB0BR1 = 0;

UCB0I2CSA = 0x48;                         // Slave Address is 048h

UCB0CTL1 &= ~UCSWRST;                     // Clear SW reset, resume operation

IE2 |= UCB0TXIE;                          // Enable TX interrupt

}

void Setup_RX(void){

_DINT();

RX = 1;

IE2 &= ~UCB0TXIE;

UCB0CTL1 |= UCSWRST;                      // Enable SW reset

UCB0CTL0

i2c通信 msp430g2553_请教 AD7150 + MSP430G2553 i2C通讯问题该如何编码??相关推荐

  1. i2c通信 msp430g2553_关于msp430G2553的I2C串行通信

    这是msp430g2xx3_uscib0_i2c_09例程,i2c从机接收数据的程序,请高手指点一下,为什么读取UCB0RXBUF是在发送中断中?接收机是在什么时候进入发送中断的? #include ...

  2. 树莓派i2c通讯 设置 和 查看 i2c通信地址方法

    一.树莓派的引脚插针i2c通讯打开 sudo raspi-config 上下方向键选择编号,左右方向键选择下面两个,我们选择第5个interfacing options 选择i2c接口 然后输入sud ...

  3. Arduino读取JY901+GPS/北斗双模定位模块信息(提高定位精度)串口和I2C通信

    Arduino读取JY901+GPS/北斗双模定位模块信息 上一篇JY901模块连接ATK-1218-BD,GPS/北斗通过JY901上位机显示数据 采用JY901的上位机查看信息后,确定JY901, ...

  4. 采用i.MX RT1020进行I2C通信实验

    目录 一.硬件概况 二.芯片内部的I2C模块基本工作机制 三.官方example代码分析(轮询) 四.I2C中断机制 五.官方example代码分析(中断) 六.I2C的DMA实现方式 七.官方exa ...

  5. 快速对比UART、SPI、I2C通信的区别与应用

    参考:带你快速对比SPI.UART.I2C通信的区别与应用! 作者:一口Linux 网址:https://mp.weixin.qq.com/s/4_RSM2jk2W6nTboO1W8HCw 电子设备之 ...

  6. STM32——stm32 I2C通信代码配置(2)(学习笔记)

    STM32--I2C通信配置 I2C的系统框架 1.通讯引脚 2.时钟控制逻辑 3.数据控制逻辑 4.整体控制逻辑 通信过程 写入过程 读取过程 I2C代码配置 I2C的初始化结构体 几个重要的函数 ...

  7. STM32的I2C通信

      STM32的两个GPIO引脚,分别用于SCL和SDA,按照I2C规约的时序,像控制LED灯那样控制引脚输出,若是接收数据时则读取SDA线上的电平,那就可以实现I2C通信了,这也是我们在51单片机上 ...

  8. (七)DSP28335基础教程——I2C通信实验(OLED显示控制)

    0 前言 本期实验目标:采用硬件I2C模块与OLED进行通信,完成显示控制. 目前发现28335比较缺乏关于I2C模块的实用例程,许多新手在配置使用该模块比较难上手,走弯路.那么通过该例程,大家则可以 ...

  9. 【单片机】I2C通信详解介绍(初学,浅显易懂,基本知识)

    介绍:I2C通讯协议(Inter-Integrated Circuit)引脚少,硬件实现简单,可扩展性强,不需要USART.CAN等通讯协议的外部收发设备,现在被广泛地使用在系统内多个集成电路(IC) ...

最新文章

  1. python常用数据结构的常用操作
  2. (深入理解)model.eval() 、model.train()以及torch.no_grad() 的区别
  3. LNMP网站并发计算
  4. php微信支付na,虚拟支付
  5. QPixmap: It is not safe to use pixmaps outside the GUI thread原因
  6. 【前端学习日记】利用Vue实现跑马灯的效果
  7. 初识Mysql(part10)--我需要知道的5种聚集函数
  8. windows和ubuntu双系统设置开机默认系统
  9. 【区块链Go语言实现】Part 1:区块链基本原型
  10. C语言之strstr函数
  11. sqlyog备份数据和导入备份数据
  12. velocity map list 数组操作
  13. Qt之QFileIconProvider
  14. selenium 模拟登录qq空间
  15. 企业运维之服务管理 -- supervisord
  16. 回溯法求解八皇后问题
  17. CF1320E Treeland and Viruses
  18. 一些基本 的数学知识
  19. 以太网 以太网地址(MAC地址)
  20. scrum立会报告+燃尽图(第三周第三次)

热门文章

  1. Win10系列:JavaScript综合实例2
  2. 一个递归函数的漏洞及优化
  3. 使用和制作patch文件
  4. 简单实现ReplaceAll(转)
  5. 加上2T硬盘再装系统遇到问题
  6. silverlight 打开html_Silverlight与HTML集成方法
  7. java lo流_javaIO:字节流
  8. 蓝牙模块引起电路干扰
  9. 100W无线电耦合功率测试实验
  10. 第十六届全国大学生智能车竞赛创意组别-航天智慧物流