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

Subversion Repositories i2cslave

[/] [i2cslave/] [trunk/] [rtl/] [i2cSlave_define.v] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sfielding
// ----------------------- i2cSlave_define.v --------------------
2
 
3
// stream states
4
`define STREAM_IDLE 2'b00
5
`define STREAM_READ 2'b01
6
`define STREAM_WRITE_ADDR 2'b10
7
`define STREAM_WRITE_DATA 2'b11
8
 
9
// start stop detection states
10
`define NULL_DET 2'b00
11
`define START_DET 2'b01
12
`define STOP_DET 2'b10
13
 
14
// i2c ack and nak
15
`define I2C_NAK 1'b1
16
`define I2C_ACK 1'b0
17
 
18
// ----------------------------------------------------------------
19
// ------------- modify constants below this line -----------------
20
// ----------------------------------------------------------------
21
 
22
// i2c device address
23
`define I2C_ADDRESS 7'h3c
24
 
25
// System clock frequency in MHz
26
// If you are using a clock frequency below 24MHz, then the macro
27
// for SDA_DEL_LEN will result in compile errors for i2cSlave.v
28
// you will need to hand tweak the SDA_DEL_LEN constant definition
29
`define CLK_FREQ 48
30
 
31
// Debounce SCL and SDA over this many clock ticks
32
// The rise time of SCL and SDA can be up to 1000nS (in standard mode)
33
// so it is essential to debounce the inputs.
34
// The spec requires 0.05V of hysteresis, but in practise
35
// simply debouncing the inputs is sufficient
36
// I2C spec requires suppresion of spikes of 
37
// maximum duration 50nS, so this debounce time should be greater than 50nS
38
// Also increases data hold time and decreases data setup time
39
// during an I2C read operation
40
// 10 ticks = 208nS @ 48MHz
41
`define DEB_I2C_LEN (10*`CLK_FREQ)/48
42
 
43
// Delay SCL for use as internal sampling clock
44
// Using delayed version of SCL to ensure that 
45
// SDA is stable when it is sampled.
46
// Not entirely citical, as according to I2C spec
47
// SDA should have a minimum of 100nS of set up time
48
// with respect to SCL rising edge. But with the very slow edge 
49
// speeds used in I2C it is better to err on the side of caution.
50
// This delay also has the effect of adding extra hold time to the data
51
// with respect to SCL falling edge. I2C spec requires 0nS of data hold time.
52
// 10 ticks = 208nS @ 48MHz
53
`define SCL_DEL_LEN (10*`CLK_FREQ)/48
54
 
55
// Delay SDA for use in start/stop detection
56
// Use delayed SDA during start/stop detection to avoid
57
// incorrect detection at SCL falling edge.
58
// From I2C spec start/stop setup is 600nS with respect to SCL rising edge
59
// and start/stop hold is 600nS wrt SCL falling edge.
60
// So it is relatively easy to discriminate start/stop,
61
// but data setup time is a minimum of 100nS with respect to SCL rising edge
62
// and 0nS hold wrt to SCL falling edge.
63
// So the tricky part is providing robust start/stop detection
64
// in the presence of regular data transitions.
65
// This delay time should be less than 100nS
66
// 4 ticks = 83nS @ 48MHz
67
`define SDA_DEL_LEN (4*`CLK_FREQ)/48
68
 

powered by: WebSVN 2.1.0

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