OpenCores
URL https://opencores.org/ocsvn/oms8051mini/oms8051mini/trunk

Subversion Repositories oms8051mini

[/] [oms8051mini/] [trunk/] [verif/] [sw/] [C/] [i2cm_burst_wrrd.c] - Blame information for rev 31

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 31 dinesha
/*
2
 * I2C Master Burst Write and Read Test
3
 *
4
 * I2C Master Write to Slave Chip with Id: 0x20
5
 *
6
 * Burst 4 Byte Write  to address starting from 0x66 with 0x12, 0x34, 0x56 and 0x78
7
 * Read Back in Burst mode and verify the expected data
8
 */
9
 
10
/*---------------------------------------------------------------------------*/
11
 
12
#include <8051.h>
13
 
14
char cErrCnt;
15
/*---------------------------------------------------------------------------*/
16
 
17
__xdata __at (0xA000) unsigned char i2c_prescale_low;
18
__xdata __at (0xA001) unsigned char i2c_prescale_high;
19
__xdata __at (0xA002) unsigned char i2c_control;
20
volatile __xdata __at (0xA003) unsigned char i2c_data;
21
volatile __xdata __at (0xA004) unsigned char i2c_cmd;
22
 
23
void main() {
24
   int ErrCnt = 0;
25
 
26
  //Wrire Prescale registers
27
   i2c_prescale_low  = 0xC7;
28
   i2c_prescale_high = 0x00;
29
 
30
  // Core Enable
31
  i2c_control = 0x80;
32
 
33
  // Writing Data
34
  i2c_data = 0x20; // Slave Addr + WR
35
  i2c_cmd  = 0x90;
36
  while(i2c_cmd & 0x2);
37
 
38
  // Memory Address 
39
  i2c_data = 0x66;
40
  i2c_cmd  = 0x10;
41
  while(i2c_cmd & 0x2);
42
 
43
 /* Byte1: 12 */
44
  i2c_data = 0x12;
45
  i2c_cmd  = 0x10;
46
  while(i2c_cmd & 0x2);
47
 
48
 /* Byte2: 34 */
49
  i2c_data = 0x34;
50
  i2c_cmd  = 0x10;
51
  while(i2c_cmd & 0x2);
52
 
53
 /* Byte3: 56 */
54
  i2c_data = 0x56;
55
  i2c_cmd  = 0x10;
56
  while(i2c_cmd & 0x2);
57
 
58
 /* Byte4: 78 */
59
  i2c_data = 0x78;
60
  i2c_cmd  = 0x50; // Stop + Write
61
  while(i2c_cmd & 0x2);
62
 
63
  //Reading Data
64
  // Slave Address + Write 
65
  i2c_data = 0x20;
66
  i2c_cmd  = 0x90;
67
  while(i2c_cmd & 0x2);
68
 
69
  // Memorry Address
70
  i2c_data = 0x66;
71
  i2c_cmd  = 0x50; // Stop 
72
  while(i2c_cmd & 0x2);
73
 
74
  //Burst Read
75
  i2c_data = 0x21;
76
  i2c_cmd  = 0x90;
77
  while(i2c_cmd & 0x2);
78
 
79
  /* BYTE-1 : 0x12  */
80
  i2c_cmd  = 0x20;
81
  while(i2c_cmd & 0x2);
82
  if(i2c_data != 0x12) ErrCnt++;
83
 
84
 
85
 
86
  /* BYTE-2 : 0x34  */
87
  i2c_cmd  = 0x20;
88
  while(i2c_cmd & 0x2);
89
  if(i2c_data != 0x34) ErrCnt++;
90
 
91
  /* BYTE-3 : 0x56  */
92
  i2c_cmd  = 0x20;
93
  while(i2c_cmd & 0x2);
94
  if(i2c_data != 0x56) ErrCnt++;
95
 
96
  /* BYTE-4 : 0x78  */
97
  i2c_cmd  = 0x68; // STOP + RD + NACK 
98
  while(i2c_cmd & 0x2);
99
  if(i2c_data != 0x78) ErrCnt++;
100
 
101
    if(ErrCnt !=0) {
102
        P2 = 0x55; // Test Fail
103
        P3 = ErrCnt;
104
 
105
    } else {
106
       P2 = 0xAA; // Test PASS
107
       P3 = 0xAA; // Test PASS
108
    }
109
 
110
    while(1);
111
 
112
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.