URL
https://opencores.org/ocsvn/rf6809/rf6809/trunk
Subversion Repositories rf6809
[/] [rf6809/] [trunk/] [software/] [boot/] [i2c.asm] - Rev 17
Go to most recent revision | Compare with Previous | Blame | View Log
; ============================================================================; __; \\__/ o\ (C) 2013-2022 Robert Finch, Waterloo; \ __ / All rights reserved.; \/_// robfinch<remove>@opencores.org; ||;;; BSD 3-Clause License; Redistribution and use in source and binary forms, with or without; modification, are permitted provided that the following conditions are met:;; 1. Redistributions of source code must retain the above copyright notice, this; list of conditions and the following disclaimer.;; 2. Redistributions in binary form must reproduce the above copyright notice,; this list of conditions and the following disclaimer in the documentation; and/or other materials provided with the distribution.;; 3. Neither the name of the copyright holder nor the names of its; contributors may be used to endorse or promote products derived from; this software without specific prior written permission.;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER; CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.;; ============================================================================;;===============================================================================; Generic I2C routines;; It is assumed there may be more than one I2C controller in the system, so; the address of the controller is passed in the X register.;===============================================================================I2C_PREL EQU $0I2C_PREH EQU $1I2C_CTRL EQU $2I2C_RXR EQU $3I2C_TXR EQU $3I2C_CMD EQU $4I2C_STAT EQU $4; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -; i2c initialization, sets the clock prescaler;; Parameters:; x = I2C controller address; Returns: none; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -i2c_init:pshs bldb #4 ; setup prescale for 400kHz clockstb I2C_PREL,xclr I2C_PREH,xpuls b,pc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -; Wait for I2C transfer to complete;; Parameters; x - I2C controller base address; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -i2c_wait_tip:pshs bi2cw1:ldb I2C_STAT,x ; would use lvb, but lb is okay since its the I/O areabitb #1 ; wait for tip to clearbne i2cw1puls b,pc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -; Write command to i2c;; Parameters; accb - data to transmit; acca - command value; x - I2C controller base address; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -i2c_wr_cmd:stb I2C_TXR,xsta I2C_CMD,xbsr i2c_wait_tipldb I2C_STAT,xrts; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -; Parameters; x - I2C controller base address; accb - data to send; Returns: none; Stack space: 2 words; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -i2c_xmit1:pshs d ; save data valuepshs d ; and save it againldb #1stb I2C_CTRL,x ; enable the coreldb #$76 ; set slave address = %0111011lda #$90 ; set STA, WRbsr i2c_wr_cmdbsr i2c_wait_rx_nackpuls d ; get back data valuelda #$50 ; set STO, WRbsr i2c_wr_cmdbsr i2c_wait_rx_nackpuls d,pc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -i2c_wait_rx_nack:pshs b ; save off accbi2cwr1:ldb I2C_STAT,x ; wait for RXack = 0bitb #$80 ; test for nackbne i2cwr1puls b,pc
Go to most recent revision | Compare with Previous | Blame | View Log
