首先,我使用使用I2C通信的mcp4725 DAC。在调试模式下,当我继续逐行代码工作并且可以在o.scope上看到转换结果,但是当我按run时,代码会运行直到完成标签,但是转换没有发生,我的意思是我看不到o.scope的结果。我该如何解决这个问题。谢谢!
;LABEL DIRECTIVE VALUE COMMENT
I2C0_MSA EQU 0x40020000 ;MASTER SLAVE ADDRESS
I2C0_MDR EQU 0x40020008 ;MASTER DATA ADDRESS
I2C0_MCS EQU 0x40020004 ;MASTER CONTROL AND STATUS REGISTER
FIRST EQU 0x20000000 ; FIRST MEMORY ADDRESS
;***************************************************************
;***************************************************************
; Program section
;***************************************************************
;LABEL DIRECTIVE VALUE COMMENT
AREA DAC, READONLY, CODE
THUMB
EXPORT I2C_DAC ; Make available
;A2=0 A1=1 A0=0
I2C_DAC PROC
LDR R0,=FIRST ;ADDRESS OF FIRST SAMPLE
;PRE-LOAD NECESSARY REGISTER VALUES
LDR R2,=I2C0_MSA;SLAVE ADDRESS
LDR R3,=I2C0_MDR ;DATA
LDR R4,=I2C0_MCS ;CONTROL STATUS
LDR R6,=0x03 ; ---0-011 START AND RUN SET
LDR R8,=0x04 ;---0-100 STOP TRANSMISSION
loop CMP R0,R7 ;R7 HOLDS LAST WRITTEN SAMPLE ADDRESS+1 WHEN IT IS REACHED TERMINATE SERIAL COMMUNICATION
BEQ done ;OTHERWISE KEEP SENDING DATA
LDRB R1,[R0],#1 ;LOAD ADC RESULT TO R1
LSL R1,#4 ;MULTIPLY BY 16 TO CONVERT 8-BIT REPRESENTATION TO 12-BIT REPRESENTATION
AND R9,R1,#0xF00;MSB 4BITS
LSR R9,#8;FIRST DATA
AND R10,R1,#0xFF ;SECOND DATA
LDR R1,=0x01 ;---0-001 KEEP TRANSMITTING
idle LDR R5,[R2]
BIC R5,#0xFF ;CLEAR MSB 8 BIT
ORR R5,#0xC4 ;GIVE 1100 DEVICE CODE 010 A2,A1 AND A0 BITS TRANSMIT OPERATION
STR R5,[R2] ;STORE SLAVE ADDRESS
LDR R5,[R3]
BIC R5,#0xFF
ORR R5,R9
STR R5,[R3] ;WRITE FIRST DATA
busbusy LDR R11,[R4] ;POLL CONTROL AND STATUS REGISTER
ANDS R11,#0x40 ;ISOLATE BUS BUSY BIT
BNE busbusy
STR R6,[R4] ;START TRANSMISSION
busy_1 LDR R11,[R4] ;POLL BUSY BIT
ANDS R12,R11,#0x01; ISOLATE BUSY BIT
BNE busy_1
error ANDS R12,R11,#0x02;ISOLATE ERROR BIT
BEQ continue
STR R8,[R4];TERMINATE TRANSMISSION IN ERROR CASE
busy_2 LDR R11,[R4] ;POLL BUSY BIT
ANDS R12,R11,#0x01; ISOLATE BUSY BIT
BNE busy_2
B idle
continue LDR R5,[R3]
BIC R5,#0xFF
ORR R5,R10
STR R5,[R3];WRITE SECOND DATA
STR R1,[R4];KEEP TRANSMITTING
busy_3 LDR R11,[R4]
ANDS R12,R11,#0x01 ;ISOLATE BUSY BIT
BNE busy_3
ANDS R12,R11,#0x02 ;ISOLATE ERROR BIT
BEQ continue1
STR R8,[R4] ;STOP TRANSMISSION IN ERROR CASE
busy_4 LDR R11,[R4] ;POLL BUSY BIT
ANDS R12,R11,#0x01; ISOLATE BUSY BIT
BNE busy_4
B idle
continue1 STR R8,[R4] ;STOP TRANSMISSION
busy_5 LDR R11,[R4] ;POLL BUSY BIT
ANDS R12,R11,#0x01; ISOLATE BUSY BIT
BNE busy_5
B loop
done BX LR
ENDP
END
答案 0 :(得分:1)
在将预期的电压和命令写入DAC之后,您应该在代码中放置一些实际继电器(1-2秒)以查看对o.scope的影响