i2c.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**********************************************************************
  2. ***********************************************************************
  3. * Software that is described herein is for illustrative purposes only
  4. * which provides customers with programming information regarding the
  5. * products. This software is supplied "AS IS" without any warranties.
  6. * NXP Semiconductors assumes no responsibility or liability for the
  7. * use of the software, conveys no license or title under any patent,
  8. * copyright, or mask work right to the product. NXP Semiconductors
  9. * reserves the right to make changes in the software without
  10. * notification. NXP Semiconductors also make no representation or
  11. * warranty that such application will be suitable for the specified
  12. * use without further testing or modification.
  13. * Permission to use, copy, modify, and distribute this software and its
  14. * documentation is hereby granted, under NXP Semiconductors�
  15. * relevant copyright in the software, without fee, provided that it
  16. * is used in conjunction with NXP Semiconductors microcontrollers. This
  17. * copyright, permission, and disclaimer notice must appear in all copies of
  18. * this code.
  19. **********************************************************************/
  20. #ifndef lpc8xx_I2C_H_
  21. #define lpc8xx_I2C_H_
  22. #include "LPC8xx.h"
  23. #define RD_BIT 0x01
  24. #define CFG_MSTENA (1 << 0)
  25. #define CFG_SLVENA (1 << 1)
  26. #define CFG_MONENA (1 << 2)
  27. #define CFG_TIMEOUTENA (1 << 3)
  28. #define CFG_MONCLKSTR (1 << 4)
  29. #define CTL_MSTCONTINUE (1 << 0)
  30. #define CTL_MSTSTART (1 << 1)
  31. #define CTL_MSTSTOP (1 << 2)
  32. #define CTL_SLVCONTINUE (1 << 0)
  33. #define CTL_SLVNACK (1 << 1)
  34. // Below matches the Niobe2 user manual
  35. #define I2C_STAT_MSTSTATE (0x7<<1)
  36. #define I2C_STAT_MSTST_IDLE (0x0<<1)
  37. #define I2C_STAT_MSTST_RX (0x1<<1)
  38. #define I2C_STAT_MSTST_TX (0x2<<1)
  39. #define STAT_MSTPEND (1 << 0)
  40. #define MASTER_STATE_MASK (0x7<<1)
  41. #define STAT_MSTIDLE (0x0 << 1)
  42. #define STAT_MSTRX (0x1 << 1)
  43. #define STAT_MSTTX (0x2 << 1)
  44. #define STAT_MSTNACKADDR (0x3 << 1)
  45. #define STAT_MSTNACKTX (0x4 << 1)
  46. #define STAT_MSTARBLOSS (1 << 4)
  47. #define STAT_MSTSSERR (1 << 6)
  48. #define STAT_SLVPEND (1 << 8)
  49. #define SLAVE_STATE_MASK (0x3<<9)
  50. #define STAT_SLVADDR (0x0 << 9)
  51. #define STAT_SLVRX (0x1 << 9)
  52. #define STAT_SLVTX (0x2 << 9)
  53. #define STAT_SLVNOTSTR (1 << 11)
  54. #define STAT_SLVSEL (1 << 14)
  55. #define STAT_SLVDESEL (1 << 15)
  56. #define STAT_MONOVERRUN (1 << 17)
  57. #define STAT_MONACTIVE (1 << 18)
  58. #define STAT_MONIDLE (1 << 19)
  59. #define STAT_EVTIMEOUT (1 << 24)
  60. #define STAT_SCLTIMEOUT (1 << 25)
  61. void WaitI2CMasterState(LPC_I2C_TypeDef * ptr_LPC_I2C, uint32_t state);
  62. void WaitI2CSlaveState(LPC_I2C_TypeDef * ptr_LPC_I2C, uint32_t state);
  63. void I2CmasterWrite( uint8_t *WrBuf, uint8_t WrLen );
  64. void I2CmasterWriteRead( uint8_t *WrBuf, uint8_t *RdBuf, uint8_t WrLen, uint8_t RdLen );
  65. #endif /* lpc8xx_I2C_H_ */