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

Subversion Repositories ssbcc

[/] [ssbcc/] [trunk/] [example/] [i2c/] [TCA9554/] [uc/] [i2c_tca9554.s] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 sinclairrf
; Copyright 2014, Sinclair R.F., Inc.
2
;
3
; Notes:
4
;   - This uses a simple board with 5 on/off switches connected to the TCA9554
5
;     on pins P0, P1, P2, P4, and P5 and with an LED connected to P3.  The 3
6
;     address pins are held to ground by pull-down resistors.
7
;   - run in 400 kHz mode
8
 
9
.constant I2C_WR_ADDR   0x40
10
.constant I2C_RD_ADDR   0x41
11
 
12
.constant I2C_INPUT     0x00
13
.constant I2C_OUTPUT    0x01
14
.constant I2C_INVERT    0x02
15
.constant I2C_CONFIG    0x03
16
 
17
.include char.s
18
 
19
.include ../../lib_i2c.s
20
 
21
.main
22
 
23
N"\r\nUC Started\r\n" .call(uart_tx)
24
 
25
; Configure P3 as an output.  Hang if a NACK is received.
26
; Note:  bit=0 ==> output, bit=1 ==> input.
27
.call(i2c_send_start)
28
.call(i2c_send_byte,I2C_WR_ADDR)
29
.call(i2c_send_byte,I2C_CONFIG)  or
30
.call(i2c_send_byte,0xF7)        or
31
.call(i2c_send_stop)
32
.jumpc(hang)
33
 
34
; Configure P3 with a low signal to turn on the LED.  Hang if a NACK is received.
35
.call(i2c_send_start)
36
.call(i2c_send_byte,I2C_WR_ADDR)
37
.call(i2c_send_byte,I2C_OUTPUT)  or
38
.call(i2c_send_byte,0xF7)        or
39
.call(i2c_send_stop)
40
.jumpc(hang)
41
 
42
; Push the current state onto the data stack.
43
.call(read_state)
44
 
45
:infinite
46
 
47
  ; Wait for the interrupt.
48
  ; Note:  This is disabled because the interrupt line either goes low for a
49
  ;        long time or goes low for a very short time.  The observed behavior
50
  ;        is not consistent with the data sheet.
51
  ; :wait_for_interrupt .inport(I_INT) 0= .jumpc(wait_for_interrupt)
52
 
53
  ; Read the device state until it changes and then display the new value.
54
  :wait_change .call(read_state) swap over - 0= .jumpc(wait_change)
55
  >r N"\r\n" r@ .call(char__byte_to_2hex) .call(uart_tx) r>
56
 
57
.jump(infinite)
58
 
59
; Error stack for NACK failure.
60
:hang
61
  N"NACK received\r\n" .call(uart_tx)
62
  :in_hang .jump(in_hang)
63
 
64
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
65
;
66
; Read the switch settings.
67
;
68
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
69
 
70
; ( - u )
71
.function read_state
72
  .call(i2c_send_start)
73
  .call(i2c_send_byte,I2C_WR_ADDR) drop
74
  .call(i2c_send_byte,I2C_INPUT)   drop
75
  .call(i2c_send_restart)
76
  .call(i2c_send_byte,I2C_RD_ADDR) drop
77
  .call(i2c_read_byte,1)
78
  .return
79
 
80
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
81
;
82
; Output the null terminated string on the data stack.
83
;
84
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
85
 
86
; ( '\0' u ... u - )
87
.function uart_tx
88
  :loop
89
    ; Wait for the UART to not be busy (there is no output FIFO).
90
    .inport(I_UART_TX_BUSY) .jumpc(loop)
91
    ; Send the next character
92
    .outport(O_UART_TX)
93
  ; Continue the loop if the next character is not the null character.
94
  .jumpc(loop,nop)
95
  ; Return and drop the terminating null character.
96
  .return(drop)

powered by: WebSVN 2.1.0

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