| ??? 12/15/06 21:08 Read: times |
#129585 - I2C C8051F310 |
Hi,
I wrote this simple application to interface an I2C device (a CODEC Chip) with C8051f310. I put a break point at "ljmp SMBus_ISR" but the code did not stop there. I put a breakpoint at "ljmp timer0_isr" and the code stopped there correctly. Please can you tell me what is that I am missing in the initialization of SMBus ISR? I have put the green LED blink routine so that I know that the main routine is running corrrectly.
;
; this program provides an example of how to configure the I2C Interface
; an internal 24500000hz crystal is used as the system clock source.;
;----------------------------------------------------------------
$include (c8051f310.inc) ; include register definition file.
;----------------------------------------------------------------; EQUATES
;----------------------------------------------------------------
GREEN_LED equ P3.3 ; Green LED: '1' is ON
SMB_MTSTA equ 0xE0 ;(MT) start transmitted
SMB_MTDB equ 0xC0 ;(MT) data byte transmitted
SMB_MRDB equ 0x80 ;(MR) data byte received
; stack
stack segment idata ; declare stack segment
rseg stack
ds 80h ; reserve 128 bytes for stack
;-----------------------------------------------------------------------------
; bit definitions
;-----------------------------------------------------------------------------
RW equ 01 ; R/W command bit. 1=READ, 0=WRITE
SMB_BUSY equ 02 ; SMBus Busy flag (kept in software)
addr_send equ 03 ; if set address sent is acknowledged
;----------------------------------------------------------------
; byte definitions
;----------------------------------------------------------------
;----------------------------------------------------------------
; reset and interrupt vector table
;----------------------------------------------------------------
cseg at 0
ljmp main
org 0bh
ljmp timer0_isr ; timer0 overflow interrupt
org 03Bh
ljmp SMBus_ISR ; SMBus Interrupt Vector
;-----------------------------------------------------------------------------
; main program code
;-----------------------------------------------------------------------------
pm33 segment code ; declare code segment
rseg pm33 ; select code segment
using 0 ; using register bank 0
;-----------------------------------------------------------------------------
; main subroutines
;-----------------------------------------------------------------------------
main:
anl pca0md, #not(040h) ; clear watchdog enable bit
mov sp, #stack-1 ; init stack pointer
clr a ; wait at least 1ms
djnz acc, $ ; wait 512us
djnz acc, $ ; wait 512us
mov r0,#07fh
clear_RAM: djnz r0,clear_RAM; to clear the RAM bytes 00 to 7Fh
call port_io_init; Initialize ports for SCL,SDA and P3.3 (LED)
mov OSCICN,#083h ; internal oscillator
lcall timer_init ; timer initialisation
lcall timer0_init ; timer 0 initialisation
acall SMBus_Init ; Initialize SMBus
lcall interrupts_init ; interrupts enable
clr GREEN_LED ; Initialize LED to OFF
Loop2: mov R7, #03h; Code to Blink LED
Loop1: mov R6, #00h
Loop0: mov R5, #00h
djnz R5, $
djnz R6, Loop0
djnz R7, Loop1
cpl GREEN_LED; Toggle LED.
jmp Loop2
;-----------------------------------------------------------------------------
; subroutines
;-----------------------------------------------------------------------------
port_io_init:
; P0.0 - SDA (SMBus), Open-Drain, Digital
; P0.1 - SCL (SMBus), Open-Drain, Digital
; P0.2 - Unassigned, Open-Drain, Digital
; P0.3 - Unassigned, Open-Drain, Digital
; P0.4 - Unassigned, Open-Drain, Digital
; P0.5 - Unassigned, Open-Drain, Digital
; P0.6 - Unassigned, Open-Drain, Digital
; P0.7 - Unassigned, Open-Drain, Digital
; P1.0 - Unassigned, Open-Drain, Digital
; P1.1 - Unassigned, Open-Drain, Digital
; P1.2 - Unassigned, Open-Drain, Digital
; P1.3 - Unassigned, Open-Drain, Digital
; P1.4 - Unassigned, Open-Drain, Digital
; P1.5 - Unassigned, Open-Drain, Digital
; P1.6 - Unassigned, Open-Drain, Digital
; P1.7 - Unassigned, Open-Drain, Digital
; P2.0 - Unassigned, Open-Drain, Digital
; P2.1 - Unassigned, Open-Drain, Digital
; P2.2 - Unassigned, Open-Drain, Digital
; P2.3 - Unassigned, Open-Drain, Digital
; P3.3 - Unassigned, Push-pull, Digital
orl P0SKIP, #04h ; skip LED pin in crossbar
mov XBR0, #004h
mov XBR1, #040h ; Enable the Port I/O Crossbar
orl P3MDOUT,#08h ; make LED pin output push-pull
orl P3MDIN, #08h ; make LED pin input mode digital
ret
;TIMER INITIALIZATON
timer_init:
mov TMOD,#002h ;Mode 2: 8-bit counter/timer with auto-reload
mov CKCON,#004h ;1:Counter/Timer 0 uses the system clock.
ret
;INTERRUPT INITIALIZATON
interrupts_init:
setb et0 ; enable timer0
orl eip1,#01 ;SMB0 interrupt set to high priority level.
setb ea ; Enable global interrupts
ret ;TIMER0 INITIALIZATON for SMBus clock source of 100 kHz
timer0_init: mov TH0,#0AFh
;100khz is bit rate from clock source
ret
;SMBUS INITIALIZATON
SMBus_Init: mov SMB0CF,#080h ;SMBUS interface enabled
setb tr0 ; Timer0 enabled
orl eie1,#01h ; Enable SMBus (SMB0) Interrupt
clr SMB_BUSY ; clear the smbus busy flag
ret
SMBus_ISR: push PSW ;
push ACC ;
SMB_ISR_END: clr SI; Clear interrupt flag
pop ACC
pop PSW
reti
; end of file.
timer0_isr: reti
end
|
| Topic | Author | Date |
| I2C C8051F310 | 01/01/70 00:00 | |
| post at silabs forum | 01/01/70 00:00 | |
| question posted | 01/01/70 00:00 | |
| Post c8051f310.inc. | 01/01/70 00:00 | |
| no link exist | 01/01/70 00:00 | |
| include file | 01/01/70 00:00 | |
| SPI interrupt address 03Bh or 033h | 01/01/70 00:00 | |
Set the STA bit to initiate the vector | 01/01/70 00:00 |



