芯片解密,芯片破解,IC解密,单片机解密,MCU解密,STM解密

飞芯科技提供芯片解密,芯片破解,IC解密,单片机解密,MCU解密,STM解密逆向服务

NXP LPC11xx I2C Slave 从机程序软件开发

  1.  软件开发Description:
  2. *     This file contains I2C slave code example which include I2C slave
  3. *     initialization, I2C slave interrupt handler, and APIs for I2C slave
  4. *     access.
  5. *
  6. ****************************************************************************
  7. * Software that is described herein is for illustrative purposes only
  8. * which provides customers with programming information regarding the
  9. * products. This software is supplied "AS IS" without any warranties.
  10. * NXP Semiconductors assumes no responsibility or liability for the
  11. * use of the software, conveys no license or title under any patent,
  12. * copyright, or mask work right to the product. NXP Semiconductors
  13. * reserves the right to make changes in the software without
  14. * notification. NXP Semiconductors also make no representation or
  15. * warranty that such application will be suitable for the specified
  16. * use without further testing or modification.
  17. ****************************************************************************/
  18. #include "LPC11xx.h"/* LPC11xx Peripheral Registers */
  19. #include "type.h"
  20. #include "i2cslave.h"

  21. volatile uint32_t I2CMasterState = I2C_IDLE;
  22. volatile uint32_t I2CSlaveState = I2C_IDLE;

  23. volatile uint32_t I2CMode;

  24. volatile uint8_t I2CWrBuffer[BUFSIZE];
  25. volatile uint8_t I2CRdBuffer[BUFSIZE];
  26. volatile uint32_t I2CReadLength;
  27. volatile uint32_t I2CWriteLength;

  28. volatile uint32_t RdIndex = 0;
  29. volatile uint32_t WrIndex = 0;

  30. /*
  31. From device to device, the I2C communication protocol may vary,
  32. in the example below, the protocol uses repeated start to read data from or
  33. write to the device:
  34. For master read: the sequence is: STA,Addr(W),offset,RE-STA,Addr(r),data...STO
  35. for master write: the sequence is: STA,Addr(W),offset,RE-STA,Addr(w),data...STO
  36. Thus, in state 8, the address is always WRITE. in state 10, the address could
  37. be READ or WRITE depending on the I2C command.
  38. */   

  39. /*****************************************************************************
  40. ** Function name:I2C_IRQHandler
  41. **
  42. ** Descriptions:I2C interrupt handler, deal with master mode only.
  43. **
  44. ** parameters:None
  45. ** Returned value:None
  46. **
  47. *****************************************************************************/
  48. void I2C_IRQHandler(void)
  49. {
  50.   uint8_t StatValue;

  51.   /* this handler deals with master read and master write only */
  52.   StatValue = LPC_I2C->STAT;
  53.   switch ( StatValue )
  54.   {
  55. case 0x60:/* An own SLA_W has been received. */
  56. case 0x68:
  57. RdIndex = 0;
  58. LPC_I2C->CONSET = I2CONSET_AA;/* assert ACK after SLV_W is received */
  59. LPC_I2C->CONCLR = I2CONCLR_SIC;
  60. I2CSlaveState = I2C_WR_STARTED;
  61. break;
  62. case 0x80:/*  data receive */
  63. case 0x90:
  64. if ( I2CSlaveState == I2C_WR_STARTED )
  65. {
  66. I2CRdBuffer[RdIndex++] = LPC_I2C->DAT;
  67. LPC_I2C->CONSET = I2CONSET_AA;/* assert ACK after data is received */
  68. }



联系方式

地址:石家庄市新华区民族路77号华强广场D座2009
电话:0311-88816616/87087811
手机:13315190088
传真:0311-67901001
联系人:张工
网址:www.taihedz.cn
邮箱:feixindz@163.com
微信:xinpianjiemi
QQ:527263666/568069805

在线客服
热线电话

企业微信