芯片解密|单片机解密|IC解密|芯片破解|芯片复制| PCB抄板|软件开发

飞芯科技-芯片解密|单片机解密|IC解密|芯片破解|芯片复制| PCB抄板|软件开发

NXP LPC11xx I2C 驱动程序单片机解密

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

  23. volatile uint32_t I2CMasterState = I2C_IDLE;
  24. volatile uint32_t I2CSlaveState = I2C_IDLE;
  25. volatile uint32_t timeout = 0;

  26. volatile uint32_t I2CMode;

  27. volatile uint8_t I2CMasterBuffer[BUFSIZE];
  28. volatile uint8_t I2CSlaveBuffer[BUFSIZE];
  29. volatile uint32_t I2CCount = 0;
  30. volatile uint32_t I2CReadLength;
  31. volatile uint32_t I2CWriteLength;

  32. volatile uint32_t RdIndex = 0;
  33. volatile uint32_t WrIndex = 0;

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

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

  55.   timeout = 0;
  56.   /* this handler deals with master read and master write only */
  57.   StatValue = LPC_I2C->STAT;
  58.   switch ( StatValue )
  59.   {
  60. case 0x08:        /* A Start condition is issued. */
  61. WrIndex = 0;
  62. LPC_I2C->DAT = I2CMasterBuffer[WrIndex++];
  63. LPC_I2C->CONCLR = (I2CONCLR_SIC | I2CONCLR_STAC);
  64. break;
  65. case 0x10:        /* A repeated started is issued */
  66. RdIndex = 0;
  67. /* Send SLA with R bit set, */
  68. LPC_I2C->DAT = I2CMasterBuffer[WrIndex++];
  69. LPC_I2C->CONCLR = (I2CONCLR_SIC | I2CONCLR_STAC);
  70. break;
  71. case 0x18:        /* Regardless, it's a ACK */
  72. if ( I2CWriteLength == 1 )
  73. {
  74. LPC_I2C->CONSET = I2CONSET_STO;      /* Set Stop flag */
  75. I2CMasterState = I2C_NO_DATA;
  76. }



联系方式

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

在线客服
热线电话

企业微信