再读IIC总线!!

 

最关键是能明白工作在四种模式(看图!!!)下的IIC总线的操作!!!

 以前在弄单片机的时候弄过IIC总线,在arm7上也弄过。如今为了写IIC总线的驱动程序,又要在arm9上弄弄了.

照惯例,先写裸机程序.

 

 

 

 

When the IIC-bus is free, the SDA and SCL lines should be both at High level. A High-to-Low transition of SDA can initiate a Start condition. A Low-to-High transition of SDA can initiate a Stop condition while SCL remains steady at
High Level.

当IIC总线为空闲的时候,SDA(数据线)SCL(时钟线)应该拉高。

SDA高到低----开始信号  低到高---- 停止信号

The Start and Stop conditions can always be generated by the master devices. A 7-bit address value in the first data byte, which is put onto the bus after the Start condition has been initiated, can determine the slave device which the
bus master device has selected. The 8th bit determines the direction of the transfer (read or write). Every data byte put onto the SDA line should be eight bits in total. The bytes can be unlimitedly sent or received
during the bus transfer operation. Data is always sent from most-significant bit (MSB) first, and every byte should be immediately followed by acknowledge (ACK) bit

第一个字节的高七位为器件地址,最低位确定读写!

每个字节发送后,从机返回一个应答信号。

 

IIC-bus master/slave Tx/Rx mode select bits.
00 : Slave receive mode
01 : Slave transmit mode
10 : Master receive mode
11 : Master transmit mode

 

很关键的模式选择!!

不同的模式,就要不同的操作! 具体看data manual上的四个图!!

 

 

贴出note!, 一些推荐使用的配置,和容易出错的地方

Notes:
1. Interfacing with EEPROM, the ack generation may be disabled before reading the last data in order to generate the STOP condition in Rx mode.

IIC总线接EEPROM时,在读最后一个数据之时,之前应该使不产生应答信号。
2. An IIC-bus interrupt occurs 1) when a 1-byte transmits or receive operation is completed, 2) when a general call or a slave address match occurs, or 3) if bus arbitration fails.
3. To adjust the setup time of SDA before SCL rising edge, IICDS has to be written before clearing the IIC interrupt pending bit.(当中断发生,如果想再次发送数据,需先写入IICDS寄存器值,然后在清楚中断标志位!)
4. IICCLK is determined by IICCON[6].
Tx clock can vary by SCL transition time.
When IICCON[6]=0, IICCON[3:0]=0x0 or 0x1 is not available.
5. If the IICCON[5]=0, IICCON[4] does not operate correctly.
So, It is recommended that you should set IICCON[5]=1, although you does not use the IIC interrupt.

即使不使用IIC的中断,推荐做法是:也要使能Tx,Rx的中断

 

 

仔细看了data manual之后,才明白原来之前我根本不懂iic

 

 

 

 

When the IIC-bus interface is inactive, it is usually in Slave mode. In other words, the interface should be in Slave
mode before detecting a Start condition on the SDA line (a Start condition can be initiated with a High-to-Low
transition of the SDA line while the clock signal of SCL is High). When the interface state is changed to Master
mode, a data transfer on the SDA line can be initiated and SCL signal generated.

在发送数据之前,总线应先处于从模式,也就是说在检测到SDA线上的开始信号之前,应处于从模式!

上面这段话,和两个工作在从模式下的两个图,看的不是很懂。似乎是一块我目前还不太懂的一个领域!(难道S3C2440可以作为挂在iic总线上的从机?越想越有可能啊! )

The following steps must be executed before any IIC Tx/Rx operations.
1) Write own slave address on IICADD register, if needed.
2) Set IICCON register.
a) Enable interrupt
b) Define SCL period
3) Set IICSTAT to enable Serial Output

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值