|
|
View previous topic :: View next topic |
Author |
Message |
mob1182
Joined: 03 Mar 2016 Posts: 28
|
I2C slave issues |
Posted: Thu Jan 12, 2017 1:36 pm |
|
|
I've been trying to do some work with I2C, sending info from one pic to another, and I'm having some strange difficulties. So I stripped my slave code down as much as I can but I still don't know what I'm doing wrong. Actually everything seems to be working fine until I add a large enough global array. Or if I add few libraries. Basically anything large enough before the INT.
Compiler PCWH 5.066
Slave code
Code: |
#include "main.h"
char get_string[65];
int i2c_flag, i;
int state[5];
int data[5];
///////////////////////////////////////////////////////////////////////////////
#int_SSP
void SSP_ISR() {
state[i] = i2c_isr_state(I2C);
data[i] = i2c_read(I2C,1);
i++;
i2c_flag++;
}
///////////////////////////////////////////////////////////////////////////////
void main() {
delay_ms(100);
set_uart_speed(9600, COM);
//--------------------------------------------------------------------------
while (true) {
fprintf(COM, "USER\r\n");
for (i=0; i<5; i++) {
state[i] = 0;
data[i] = 0;
}
i2c_flag = 0;
i = 0;
clear_interrupt(INT_SSP);
enable_interrupts(INT_SSP);
enable_interrupts(GLOBAL);
while (!i2c_flag) {
delay_us(1);
}
delay_ms(500);
disable_interrupts(GLOBAL);
disable_interrupts(INT_SSP);
for (i=0; i < 5; i++) {
fprintf(COM, "state[%u] = %u\r\n", i, state[i]);
fprintf(COM, "data[%u] = %u\r\n", i, data[i]);
}
}
}
|
slave main.h
Code: |
#include <18F47K40.h>
#DEVICE ADC=10
#FUSES NOPPS1WAY
#FUSES NOEXTOSC
//#FUSES NOMCLR //MCLR on pull up and spst
#FUSES NOBROWNOUT
#FUSES NOLVP
#FUSES NOWDT
#FUSES NOPROTECT
#FUSES PUT
#USE delay(internal=64MHz)
//=============================================================================
// PIN SELECTS
//=============================================================================
#PIN_SELECT SCL1IN = PIN_C3
#PIN_SELECT SCL1OUT = PIN_C3
#PIN_SELECT SDA1IN = PIN_C4
#PIN_SELECT SDA1OUT = PIN_C4
#PIN_SELECT SCL2IN = PIN_B1
#PIN_SELECT SCL2OUT = PIN_B1
#PIN_SELECT SDA2IN = PIN_B2
#PIN_SELECT SDA2OUT = PIN_B2
#PIN_SELECT U1TX = PIN_C6
#PIN_SELECT U1RX = PIN_C7
//=============================================================================
#USE RS232(UART1, BAUD=9600, PARITY=N, BITS=8, ERRORS, STREAM=COM)
#USE I2C(I2C1, slave, address = 0xA0, STREAM=I2C)
|
some of the master
function - pKeyword[1] hold the string that will be sent to the slave
Code: |
void send_slave() {
int i, len;
int send[10];
len = strlen(pKeyword[1]);
fprintf(COM, "word = %s\r\n", pKeyword[1]);
fprintf(COM, "len = %u\r\n", len);
for (i=0; i<len; i++) {
send[i] = *(pKeyword[1] + i);
fprintf(COM, "send[%u] = %u\r\n", i, send[i]);
}
i2c_start(I2C); //start
i2c_write(I2C, 0XA0); //address
for (i=0; i<len; i++) { //data
i2c_write(I2C, send[i]);
}
i2c_stop(I2C); //stop
}
|
master main.h
Code: |
#include <18F47K40.h>
//=============================================================================
//The compiler is not setting these addressess correctly so unitil there is an
//update manually set these(Ignore duplicate locates during compile)
//=============================================================================
#word CCP_1 = 0xFAA
#byte CCP_1_LOW = 0xFAA
#byte CCP_1_HIGH = 0xFAB
#word CCP_2 = 0xFA6
#byte CCP_2_LOW = 0xFA6
#byte CCP_2_HIGH = 0xFA7
//=============================================================================
// MCU OPTIONS
//=============================================================================
#DEVICE ADC=10
//=============================================================================
// MCU CONFIGUARTION WORDS
//=============================================================================
#FUSES NOPPS1WAY
#FUSES NOEXTOSC //External Oscillator not enabled
#FUSES CLKOUT //Clockout on Pin 14
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES NOBROWNOUT //No Brownout Reset
#FUSES NOLVP //No Low Voltage Programming, B5 used for I/O
#FUSES NOWDT //No Watchdog Timer
#FUSES NOPROTECT //
#FUSES PUT //Power Up Timer
#USE delay(internal=64MHz, clock_out)
//=============================================================================
// PIN SELECTS
//=============================================================================
#PIN_SELECT CCP1 = PIN_C2
#PIN_SELECT CCP2 = PIN_C1
#PIN_SELECT SCL1IN = PIN_C3 //The I2C1_SCL #DEFINE must equal this
#PIN_SELECT SCL1OUT = PIN_C3 //The I2C1_SCL #DEFINE must equal this
#PIN_SELECT SDA1IN = PIN_C4 //The I2C1_SDA #DEFINE must equal this
#PIN_SELECT SDA1OUT = PIN_C4 //The I2C1_SDA #DEFINE must equal this
#PIN_SELECT SCL2IN = PIN_B1
#PIN_SELECT SCL2OUT = PIN_B1
#PIN_SELECT SDA2IN = PIN_B2
#PIN_SELECT SDA2OUT = PIN_B2
#PIN_SELECT U1RX = PIN_C7
#PIN_SELECT U1TX = PIN_C6
#PIN_SELECT U2RX = PIN_B5
#PIN_SELECT U2TX = PIN_B4
//=============================================================================
// INITIAL STREAM SETUPS
//=============================================================================
#USE RS232(UART1, BAUD=9600, PARITY=N, BITS=8, ERRORS, STREAM=COM)
#USE RS232(UART2, BAUD=9600, PARITY=N, BITS=8, ERRORS, STREAM=USB)
#USE RS232(BAUD=2400, XMIT=PIN_E1, RCV=PIN_E2, STREAM = MOTOR)
#USE I2C(MASTER, I2C1, STREAM=EEPROM)
#USE I2C(MASTER, I2C2, STREAM=I2C)
|
The master is on a picdem labII and the slave is on an explorer 8(this is why the nomclr is commented out in the slave code).
If my get_string is anything less than 66 it works fine
If I send the string "o2"
master sends to teraterm
Quote: |
word = o2
len = 2
send[0] = 111
send[1] = 50
|
slave sends
Quote: |
USER
state[0] = 0
data[0] = 160
state[1] = 1
data[1] = 111
state[2] = 2
data[2] = 50
state[3] = 0
data[3] = 0
state[4] = 0
data[4] = 0
USER
|
So it "appears" to work
but when get_string is 67
master sends to teraterm
Quote: |
word = o2
len = 2
send[0] = 111
send[1] = 50
|
slave sends
Quote: |
USER
state[0] = 0
data[0] = 0
state[1] = 0
data[1] = 0
state[2] = 0
data[2] = 0
state[3] = 0
data[3] = 0
state[4] = 0
data[4] = 0
USER
|
Now this is strange cause the print should even happen if it didn't enter the interrupt, but since it did why is it all 0's
Now if get_string is 68 nothing happens on the slave end at all
In all 3 situations I can verify that the same exact data is being sent
Using 2.2k Pull up resistors. I know I'm going off board here with jumper wires but the rise time is currently well within spec. I also have the grounds of both boards tied together.
Im new to I2C so I'm sure im missing something but after looking through manuals all day I can't seem to find what it is. Any help would be greatly appreciated! Thanks!
additional info
lst with get_string 65
Quote: |
ROM used: 1102 bytes (1%)
Largest free fragment is 65536
RAM used: 110 (3%) at main() level
116 (3%) worst case
Stack used: 2 locations (1 in main + 1 for interrupts)
Stack size: 31
*
00000: GOTO MAIN
*
00008: MOVWF 04
0000A: MOVFF STATUS,05
0000E: MOVFF BSR,06
00012: MOVLB 0
00014: MOVFF FSR0L,0C
00018: MOVFF FSR0H,07
0001C: MOVFF FSR1L,08
00020: MOVFF FSR1H,09
00024: MOVFF FSR2L,0A
00028: MOVFF FSR2H,0B
0002C: MOVFF PRODL,12
00030: MOVFF PRODH,13
00034: MOVFF PCLATH,14
00038: MOVFF TABLAT,15
0003C: MOVFF TBLPTRL,16
00040: MOVFF TBLPTRH,17
00044: MOVFF TBLPTRU,18
00048: MOVFF PCLATU,19
0004C: MOVFF 00,0E
00050: MOVFF 01,0F
00054: MOVFF 02,10
00058: MOVFF 03,11
0005C: MOVLB E
0005E: BTFSS xC5.0
00060: GOTO 006A
00064: BTFSC xCD.0
00066: GOTO 00C0
0006A: MOVFF 0E,00
0006E: MOVFF 0F,01
00072: MOVFF 10,02
00076: MOVFF 11,03
0007A: MOVFF 0C,FSR0L
0007E: MOVFF 07,FSR0H
00082: BSF 07.7
00084: MOVFF 08,FSR1L
00088: MOVFF 09,FSR1H
0008C: MOVFF 0A,FSR2L
00090: MOVFF 0B,FSR2H
00094: MOVFF 12,PRODL
00098: MOVFF 13,PRODH
0009C: MOVFF 14,PCLATH
000A0: MOVFF 15,TABLAT
000A4: MOVFF 16,TBLPTRL
000A8: MOVFF 17,TBLPTRH
000AC: MOVFF 18,TBLPTRU
000B0: MOVFF 19,PCLATU
000B4: MOVF 04,W
000B6: MOVFF 06,BSR
000BA: MOVFF 05,STATUS
000BE: RETFIE 0
.................... #include "main.h"
.................... #include <18F47K40.h>
.................... //////////// Standard Header file for the PIC18F47K40 device ////////////////
.................... ///////////////////////////////////////////////////////////////////////////
.................... //// (C) Copyright 1996, 2014 Custom Computer Services ////
.................... //// This source code may only be used by licensed users of the CCS C ////
.................... //// compiler. This source code may only be distributed to other ////
.................... //// licensed users of the CCS C compiler. No other use, reproduction ////
.................... //// or distribution is permitted without written permission. ////
.................... //// Derivative programs created using this software in object code ////
.................... //// form are not restricted in any way. ////
.................... ///////////////////////////////////////////////////////////////////////////
.................... #device PIC18F47K40
*
00106: DATA 55,53
00108: DATA 45,52
0010A: DATA 0D,0A
0010C: DATA 00,00
0010E: DATA 73,74
00110: DATA 61,74
00112: DATA 65,5B
00114: DATA 25,75
00116: DATA 5D,20
00118: DATA 3D,20
0011A: DATA 25,75
0011C: DATA 0D,0A
0011E: DATA 00,00
00120: DATA 64,61
00122: DATA 74,61
00124: DATA 5B,25
00126: DATA 75,5D
00128: DATA 20,20
0012A: DATA 3D,20
0012C: DATA 25,75
0012E: DATA 0D,0A
00130: DATA 00,00
*
0015A: TBLRD*+
0015C: MOVF TABLAT,F
0015E: BZ 0186
00160: MOVFF TBLPTRL,@@6C
00164: MOVFF TBLPTRH,@@6D
00168: MOVFF TBLPTRU,@@6E
0016C: MOVF TABLAT,W
0016E: MOVLB E
00170: BTFSS xCD.4
00172: BRA 0170
00174: MOVWF TX1REG
00176: MOVFF @@6C,TBLPTRL
0017A: MOVFF @@6D,TBLPTRH
0017E: MOVFF @@6E,TBLPTRU
00182: MOVLB 0
00184: BRA 015A
00186: GOTO 0320 (RETURN)
0018A: TBLRD*+
0018C: MOVFF TBLPTRL,@@6E
00190: MOVFF TBLPTRH,@@6F
00194: MOVFF TBLPTRU,@@70
00198: MOVF TABLAT,W
0019A: MOVLB E
0019C: BTFSS xCD.4
0019E: BRA 019C
001A0: MOVWF TX1REG
001A2: MOVFF @@6E,TBLPTRL
001A6: MOVFF @@6F,TBLPTRH
001AA: MOVFF @@70,TBLPTRU
001AE: MOVLB 0
001B0: DECFSZ ??65535,F
001B2: BRA 018A
001B4: RETURN 0
001B6: MOVF @DIV88.P1,W
001B8: CLRF @01
001BA: SUBWF ??65535,W
001BC: BC 01C4
001BE: MOVFF ??65535,00
001C2: BRA 01DC
001C4: CLRF @00
001C6: MOVLW 08
001C8: MOVWF @@x71
001CA: RLCF ??65535,F
001CC: RLCF @00,F
001CE: MOVF @DIV88.P1,W
001D0: SUBWF @00,W
001D2: BTFSC STATUS.C
001D4: MOVWF @00
001D6: RLCF @01,F
001D8: DECFSZ @@x71,F
001DA: BRA 01CA
001DC: RETURN 0
001DE: MOVF @01,W
001E0: MOVFF ??65535,??65535
001E4: MOVLW 64
001E6: MOVWF @DIV88.P1
001E8: RCALL 01B6
001EA: MOVFF 00,??65535
001EE: MOVF @01,W
001F0: MOVLW 30
001F2: BNZ 0202
001F4: BTFSS @PRINTF_U_9600_31870_31871.P1.1
001F6: BRA 0216
001F8: BTFSC @PRINTF_U_9600_31870_31871.P1.3
001FA: BRA 0216
001FC: BTFSC @PRINTF_U_9600_31870_31871.P1.4
001FE: MOVLW 20
00200: BRA 0208
00202: BCF @PRINTF_U_9600_31870_31871.P1.3
00204: BCF @PRINTF_U_9600_31870_31871.P1.4
00206: BSF @PRINTF_U_9600_31870_31871.P1.0
00208: ADDWF @01,F
0020A: MOVF @01,W
0020C: MOVLB E
0020E: BTFSS xCD.4
00210: BRA 020E
00212: MOVWF TX1REG
00214: MOVLB 0
00216: MOVFF ??65535,??65535
0021A: MOVLW 0A
0021C: MOVWF @DIV88.P1
0021E: RCALL 01B6
00220: MOVFF 00,??65535
00224: MOVF @01,W
00226: MOVLW 30
00228: BNZ 0236
0022A: BTFSC @PRINTF_U_9600_31870_31871.P1.3
0022C: BRA 0244
0022E: BTFSS @PRINTF_U_9600_31870_31871.P1.0
00230: BRA 0244
00232: BTFSC @PRINTF_U_9600_31870_31871.P1.4
00234: MOVLW 20
00236: ADDWF @01,F
00238: MOVF @01,W
0023A: MOVLB E
0023C: BTFSS xCD.4
0023E: BRA 023C
00240: MOVWF TX1REG
00242: MOVLB 0
00244: MOVLW 30
00246: ADDWF ??65535,F
00248: MOVF ??65535,W
0024A: MOVLB E
0024C: BTFSS xCD.4
0024E: BRA 024C
00250: MOVWF TX1REG
00252: MOVLB 0
00254: RETURN 0
....................
.................... #list
....................
.................... #DEVICE ADC=10
....................
.................... #FUSES NOPPS1WAY
.................... #FUSES NOEXTOSC
.................... //#FUSES NOMCLR //MCLR on pull up and spst
.................... #FUSES NOBROWNOUT
.................... #FUSES NOLVP
.................... #FUSES NOWDT
.................... #FUSES NOPROTECT
.................... #FUSES PUT
.................... #USE delay(internal=64MHz)
*
00132: CLRF FSR0H
00134: MOVLW ??65535
00136: MOVWF FSR0L
00138: MOVF INDF0,W
0013A: BZ 0158
0013C: MOVLW 14
0013E: MOVWF @01
00140: CLRF @00
00142: DECFSZ @00,F
00144: BRA 0142
00146: DECFSZ @01,F
00148: BRA 0140
0014A: MOVLW BF
0014C: MOVWF @00
0014E: DECFSZ @00,F
00150: BRA 014E
00152: BRA 0154
00154: DECFSZ INDF0,F
00156: BRA 013C
00158: RETURN 0
.................... //=============================================================================
.................... // PIN SELECTS
.................... //=============================================================================
.................... #PIN_SELECT SCL1IN = PIN_C3
.................... #PIN_SELECT SCL1OUT = PIN_C3
.................... #PIN_SELECT SDA1IN = PIN_C4
.................... #PIN_SELECT SDA1OUT = PIN_C4
....................
.................... #PIN_SELECT SCL2IN = PIN_B1
.................... #PIN_SELECT SCL2OUT = PIN_B1
.................... #PIN_SELECT SDA2IN = PIN_B2
.................... #PIN_SELECT SDA2OUT = PIN_B2
....................
.................... #PIN_SELECT U1TX = PIN_C6
.................... #PIN_SELECT U1RX = PIN_C7
.................... //=============================================================================
.................... #USE RS232(UART1, BAUD=9600, PARITY=N, BITS=8, ERRORS, STREAM=COM)
.................... #USE I2C(I2C1, slave, address = 0xA0, STREAM=I2C)
....................
....................
....................
....................
....................
.................... char get_string[65];
....................
.................... int i2c_flag, i;
.................... int state[5];
.................... int data[5];
.................... ///////////////////////////////////////////////////////////////////////////////
.................... #int_SSP
.................... void SSP_ISR() {
.................... state[i] = i2c_isr_state(I2C);
*
000C0: CLRF @03
000C2: MOVF i,W
000C4: ADDLW state
000C6: MOVWF FSR0L
000C8: MOVLW state+-95
000CA: ADDWFC @03,W
000CC: MOVWF FSR0H
000CE: BTFSC SSP1STAT.A
000D0: BRA 00D8
000D2: CLRF @I2C_STATE
000D4: BTFSC SSP1STAT.W
000D6: BSF @I2C_STATE.7
000D8: MOVF @I2C_STATE,W
000DA: INCF @I2C_STATE,F
000DC: MOVWF INDF0
.................... data[i] = i2c_read(I2C,1);
000DE: CLRF @03
000E0: MOVF i,W
000E2: ADDLW data
000E4: MOVWF FSR0L
000E6: MOVLW data+-100
000E8: ADDWFC @03,W
000EA: MOVWF FSR0H
000EC: BCF SSP1CON1.SSPOV
000EE: BTFSS SSP1STAT.BF
000F0: BRA 00EE
000F2: MOVF SSP1BUF,W
000F4: BSF SSP1CON1.CKP
000F6: MOVWF INDF0
.................... i++;
000F8: INCF i,F
.................... i2c_flag++;
000FA: INCF i2c_flag,F
000FC: MOVLB E
000FE: BCF xCD.0
00100: MOVLB 0
00102: GOTO 006A
.................... }
.................... ///////////////////////////////////////////////////////////////////////////////
.................... void main() {
*
00256: BSF NVMCON1.NVMREG1
00258: BCF NVMCON1.NVMREG0
0025A: CLRF TBLPTRU
0025C: BCF T1GCON.GE
0025E: BSF 07.7
00260: MOVLB E
00262: MOVLW 55
00264: MOVWF xA0
00266: MOVLW AA
00268: MOVWF xA0
0026A: BCF xA0.0
0026C: MOVLW 17
0026E: MOVWF xB5
00270: MOVLW 13
00272: MOVWF xB7
00274: MOVLW 14
00276: MOVWF xB8
00278: MOVLW 09
0027A: MOVWF x8F
0027C: MOVLW 0A
0027E: MOVWF x90
00280: MOVLW 11
00282: MOVWF xF0
00284: MOVLW 12
00286: MOVWF xF1
00288: MOVLW 0F
0028A: MOVWF xFA
0028C: MOVLW 10
0028E: MOVWF xFB
00290: MOVLW 09
00292: MOVWF xFD
00294: MOVLW 55
00296: MOVWF xA0
00298: MOVLW AA
0029A: MOVWF xA0
0029C: BSF xA0.0
0029E: CLRF xDD
002A0: CLRF xDA
002A2: CLRF xDC
002A4: MOVLW 08
002A6: MOVWF xDE
002A8: MOVLW 60
002AA: MOVWF xD8
002AC: CLRF rs232_errors
002AE: BSF BAUD1CON.BRG16
002B0: MOVLW 82
002B2: MOVWF SP1BRGL
002B4: MOVLW 06
002B6: MOVWF SP1BRGH
002B8: MOVLW A6
002BA: MOVWF TX1STA
002BC: MOVLW 90
002BE: MOVWF RC1STA
002C0: BSF TRISC.3
002C2: BSF TRISC.4
002C4: MOVLW A0
002C6: MOVWF SSP1ADD
002C8: SETF SSP1MSK
002CA: MOVLW 36
002CC: MOVWF SSP1CON1
002CE: BSF SSP1CON2.SEN
002D0: BSF SSP1CON2.GCEN
002D2: MOVLW 03
002D4: MOVLB 0
002D6: MOVWF @I2C_STATE
002D8: CLRF @sprintf_string+1
002DA: CLRF @sprintf_string
002DC: MOVLB F
002DE: CLRF x11
002E0: CLRF x19
002E2: CLRF x21
002E4: CLRF x26
002E6: CLRF x2E
002E8: CLRF x3A
002EA: CLRF x3B
002EC: CLRF x3C
002EE: CLRF x39
002F0: CLRF x36
002F2: CLRF x37
002F4: CLRF x38
002F6: CLRF x35
.................... delay_ms(100);
002F8: MOVLW 64
002FA: MOVLB 0
002FC: MOVWF ??65535
002FE: RCALL 0132
.................... set_uart_speed(9600, COM);
00300: BSF BAUD1CON.BRG16
00302: MOVLW 82
00304: MOVWF SP1BRGL
00306: MOVLW 06
00308: MOVWF SP1BRGH
0030A: MOVLW A6
0030C: MOVWF TX1STA
0030E: MOVLW 90
00310: MOVWF RC1STA
.................... //--------------------------------------------------------------------------
.................... while (true) {
.................... fprintf(COM, "USER\r\n");
00312: MOVLW 06
00314: MOVWF TBLPTRL
00316: MOVLW 01
00318: MOVWF TBLPTRH
0031A: MOVLW 00
0031C: MOVWF TBLPTRU
0031E: BRA 015A
.................... for (i=0; i<5; i++) {
00320: CLRF i
00322: MOVF i,W
00324: SUBLW 04
00326: BNC 034C
.................... state[i] = 0;
00328: CLRF @03
0032A: MOVF i,W
0032C: ADDLW state
0032E: MOVWF FSR0L
00330: MOVLW state+-95
00332: ADDWFC @03,W
00334: MOVWF FSR0H
00336: CLRF INDF0
.................... data[i] = 0;
00338: CLRF @03
0033A: MOVF i,W
0033C: ADDLW data
0033E: MOVWF FSR0L
00340: MOVLW data+-100
00342: ADDWFC @03,W
00344: MOVWF FSR0H
00346: CLRF INDF0
00348: INCF i,F
0034A: BRA 0322
.................... }
.................... i2c_flag = 0;
0034C: CLRF i2c_flag
.................... i = 0;
0034E: CLRF i
.................... clear_interrupt(INT_SSP);
00350: MOVLB E
00352: BCF xCD.0
.................... enable_interrupts(INT_SSP);
00354: BSF xC5.0
.................... enable_interrupts(GLOBAL);
00356: MOVLW C0
00358: IORWF INTCON,F
.................... while (!i2c_flag) {
0035A: MOVF i2c_flag,F
0035C: BNZ 0368
.................... delay_us(1);
0035E: MOVLW 05
00360: MOVWF @00
00362: DECFSZ @00,F
00364: BRA 0362
00366: BRA 035A
.................... }
.................... delay_ms(500);
00368: MOVLW 02
0036A: MOVLB 0
0036C: MOVWF @@x6C
0036E: MOVLW FA
00370: MOVWF ??65535
00372: RCALL 0132
00374: DECFSZ @@x6C,F
00376: BRA 036E
.................... disable_interrupts(GLOBAL);
00378: BCF INTCON.GIEL
0037A: BCF INTCON.GIEH
0037C: BTFSC INTCON.GIEH
0037E: BRA 037A
.................... disable_interrupts(INT_SSP);
00380: MOVLB E
00382: BCF xC5.0
.................... for (i=0; i < 5; i++) {
00384: CLRF i
00386: MOVF i,W
00388: SUBLW 04
0038A: BNC 044C
.................... fprintf(COM, "state[%u] = %u\r\n", i, state[i]);
0038C: CLRF @03
0038E: MOVF i,W
00390: ADDLW state
00392: MOVWF FSR0L
00394: MOVLW state+-95
00396: ADDWFC @03,W
00398: MOVWF FSR0H
0039A: MOVFF INDF0,@@6C
0039E: MOVLW 0E
003A0: MOVWF TBLPTRL
003A2: MOVLW 01
003A4: MOVWF TBLPTRH
003A6: MOVLW 00
003A8: MOVWF TBLPTRU
003AA: MOVLW 06
003AC: MOVLB 0
003AE: MOVWF ??65535
003B0: RCALL 018A
003B2: MOVFF i,??65535
003B6: MOVLW 1B
003B8: MOVWF @PRINTF_U_9600_31870_31871.P1
003BA: RCALL 01DE
003BC: MOVLW 16
003BE: MOVWF TBLPTRL
003C0: MOVLW 01
003C2: MOVWF TBLPTRH
003C4: MOVLW 00
003C6: MOVWF TBLPTRU
003C8: MOVLW 04
003CA: MOVWF ??65535
003CC: RCALL 018A
003CE: MOVFF @@6C,??65535
003D2: MOVLW 1B
003D4: MOVWF @PRINTF_U_9600_31870_31871.P1
003D6: RCALL 01DE
003D8: MOVLW 0D
003DA: MOVLB E
003DC: BTFSS xCD.4
003DE: BRA 03DC
003E0: MOVWF TX1REG
003E2: MOVLW 0A
003E4: BTFSS xCD.4
003E6: BRA 03E4
003E8: MOVWF TX1REG
.................... fprintf(COM, "data[%u] = %u\r\n", i, data[i]);
003EA: CLRF @03
003EC: MOVF i,W
003EE: ADDLW data
003F0: MOVWF FSR0L
003F2: MOVLW data+-100
003F4: ADDWFC @03,W
003F6: MOVWF FSR0H
003F8: MOVFF INDF0,@@6C
003FC: MOVLW 20
003FE: MOVWF TBLPTRL
00400: MOVLW 01
00402: MOVWF TBLPTRH
00404: MOVLW 00
00406: MOVWF TBLPTRU
00408: MOVLW 05
0040A: MOVLB 0
0040C: MOVWF ??65535
0040E: RCALL 018A
00410: MOVFF i,??65535
00414: MOVLW 1B
00416: MOVWF @PRINTF_U_9600_31870_31871.P1
00418: RCALL 01DE
0041A: MOVLW 27
0041C: MOVWF TBLPTRL
0041E: MOVLW 01
00420: MOVWF TBLPTRH
00422: MOVLW 00
00424: MOVWF TBLPTRU
00426: MOVLW 05
00428: MOVWF ??65535
0042A: RCALL 018A
0042C: MOVFF @@6C,??65535
00430: MOVLW 1B
00432: MOVWF @PRINTF_U_9600_31870_31871.P1
00434: RCALL 01DE
00436: MOVLW 0D
00438: MOVLB E
0043A: BTFSS xCD.4
0043C: BRA 043A
0043E: MOVWF TX1REG
00440: MOVLW 0A
00442: BTFSS xCD.4
00444: BRA 0442
00446: MOVWF TX1REG
00448: INCF i,F
0044A: BRA 0386
.................... }
0044C: MOVLB 0
0044E: BRA 0312
.................... }
.................... }
....................
00450: SLEEP
....................
....................
....................
Configuration Fuses:
Word 1: 2904 NOEXTOSC RSTOSC_HFINTRC_64MHZ NOCLKOUT CKS FCMEN
Word 2: B721 MCLR PUT NOLPBOR NOBROWNOUT BORV24 ZCDDIS NOPPS1WAY STVREN NODEBUG NOXINST
Word 3: 3F1F WDTSW NOWDT WDTWIN_SW WDTCLK_SW
Word 4: 17FF NOWRT NOWRTC NOWRTB NOWRTD SCANE NOLVP
Word 5: 0003 NOPROTECT NOCPD
Word 6: 02FF NOEBTR NOEBTRB
|
lst with get string 68
Quote: |
ROM used: 1102 bytes (1%)
Largest free fragment is 65536
RAM used: 113 (3%) at main() level
119 (3%) worst case
Stack used: 2 locations (1 in main + 1 for interrupts)
Stack size: 31
*
00000: GOTO MAIN
*
00008: MOVWF 04
0000A: MOVFF STATUS,05
0000E: MOVFF BSR,06
00012: MOVLB 0
00014: MOVFF FSR0L,0C
00018: MOVFF FSR0H,07
0001C: MOVFF FSR1L,08
00020: MOVFF FSR1H,09
00024: MOVFF FSR2L,0A
00028: MOVFF FSR2H,0B
0002C: MOVFF PRODL,12
00030: MOVFF PRODH,13
00034: MOVFF PCLATH,14
00038: MOVFF TABLAT,15
0003C: MOVFF TBLPTRL,16
00040: MOVFF TBLPTRH,17
00044: MOVFF TBLPTRU,18
00048: MOVFF PCLATU,19
0004C: MOVFF 00,0E
00050: MOVFF 01,0F
00054: MOVFF 02,10
00058: MOVFF 03,11
0005C: MOVLB E
0005E: BTFSS xC5.0
00060: GOTO 006A
00064: BTFSC xCD.0
00066: GOTO 00C0
0006A: MOVFF 0E,00
0006E: MOVFF 0F,01
00072: MOVFF 10,02
00076: MOVFF 11,03
0007A: MOVFF 0C,FSR0L
0007E: MOVFF 07,FSR0H
00082: BSF 07.7
00084: MOVFF 08,FSR1L
00088: MOVFF 09,FSR1H
0008C: MOVFF 0A,FSR2L
00090: MOVFF 0B,FSR2H
00094: MOVFF 12,PRODL
00098: MOVFF 13,PRODH
0009C: MOVFF 14,PCLATH
000A0: MOVFF 15,TABLAT
000A4: MOVFF 16,TBLPTRL
000A8: MOVFF 17,TBLPTRH
000AC: MOVFF 18,TBLPTRU
000B0: MOVFF 19,PCLATU
000B4: MOVF 04,W
000B6: MOVFF 06,BSR
000BA: MOVFF 05,STATUS
000BE: RETFIE 0
.................... #include "main.h"
.................... #include <18F47K40.h>
.................... //////////// Standard Header file for the PIC18F47K40 device ////////////////
.................... ///////////////////////////////////////////////////////////////////////////
.................... //// (C) Copyright 1996, 2014 Custom Computer Services ////
.................... //// This source code may only be used by licensed users of the CCS C ////
.................... //// compiler. This source code may only be distributed to other ////
.................... //// licensed users of the CCS C compiler. No other use, reproduction ////
.................... //// or distribution is permitted without written permission. ////
.................... //// Derivative programs created using this software in object code ////
.................... //// form are not restricted in any way. ////
.................... ///////////////////////////////////////////////////////////////////////////
.................... #device PIC18F47K40
*
00106: DATA 55,53
00108: DATA 45,52
0010A: DATA 0D,0A
0010C: DATA 00,00
0010E: DATA 73,74
00110: DATA 61,74
00112: DATA 65,5B
00114: DATA 25,75
00116: DATA 5D,20
00118: DATA 3D,20
0011A: DATA 25,75
0011C: DATA 0D,0A
0011E: DATA 00,00
00120: DATA 64,61
00122: DATA 74,61
00124: DATA 5B,25
00126: DATA 75,5D
00128: DATA 20,20
0012A: DATA 3D,20
0012C: DATA 25,75
0012E: DATA 0D,0A
00130: DATA 00,00
*
0015A: TBLRD*+
0015C: MOVF TABLAT,F
0015E: BZ 0186
00160: MOVFF TBLPTRL,@@6F
00164: MOVFF TBLPTRH,@@70
00168: MOVFF TBLPTRU,@@71
0016C: MOVF TABLAT,W
0016E: MOVLB E
00170: BTFSS xCD.4
00172: BRA 0170
00174: MOVWF TX1REG
00176: MOVFF @@6F,TBLPTRL
0017A: MOVFF @@70,TBLPTRH
0017E: MOVFF @@71,TBLPTRU
00182: MOVLB 0
00184: BRA 015A
00186: GOTO 0320 (RETURN)
0018A: TBLRD*+
0018C: MOVFF TBLPTRL,@@71
00190: MOVFF TBLPTRH,@@72
00194: MOVFF TBLPTRU,@@73
00198: MOVF TABLAT,W
0019A: MOVLB E
0019C: BTFSS xCD.4
0019E: BRA 019C
001A0: MOVWF TX1REG
001A2: MOVFF @@71,TBLPTRL
001A6: MOVFF @@72,TBLPTRH
001AA: MOVFF @@73,TBLPTRU
001AE: MOVLB 0
001B0: DECFSZ ??65535,F
001B2: BRA 018A
001B4: RETURN 0
001B6: MOVF @DIV88.P1,W
001B8: CLRF @01
001BA: SUBWF ??65535,W
001BC: BC 01C4
001BE: MOVFF ??65535,00
001C2: BRA 01DC
001C4: CLRF @00
001C6: MOVLW 08
001C8: MOVWF @@x74
001CA: RLCF ??65535,F
001CC: RLCF @00,F
001CE: MOVF @DIV88.P1,W
001D0: SUBWF @00,W
001D2: BTFSC STATUS.C
001D4: MOVWF @00
001D6: RLCF @01,F
001D8: DECFSZ @@x74,F
001DA: BRA 01CA
001DC: RETURN 0
001DE: MOVF @01,W
001E0: MOVFF ??65535,??65535
001E4: MOVLW 64
001E6: MOVWF @DIV88.P1
001E8: RCALL 01B6
001EA: MOVFF 00,??65535
001EE: MOVF @01,W
001F0: MOVLW 30
001F2: BNZ 0202
001F4: BTFSS @PRINTF_U_9600_31870_31871.P1.1
001F6: BRA 0216
001F8: BTFSC @PRINTF_U_9600_31870_31871.P1.3
001FA: BRA 0216
001FC: BTFSC @PRINTF_U_9600_31870_31871.P1.4
001FE: MOVLW 20
00200: BRA 0208
00202: BCF @PRINTF_U_9600_31870_31871.P1.3
00204: BCF @PRINTF_U_9600_31870_31871.P1.4
00206: BSF @PRINTF_U_9600_31870_31871.P1.0
00208: ADDWF @01,F
0020A: MOVF @01,W
0020C: MOVLB E
0020E: BTFSS xCD.4
00210: BRA 020E
00212: MOVWF TX1REG
00214: MOVLB 0
00216: MOVFF ??65535,??65535
0021A: MOVLW 0A
0021C: MOVWF @DIV88.P1
0021E: RCALL 01B6
00220: MOVFF 00,??65535
00224: MOVF @01,W
00226: MOVLW 30
00228: BNZ 0236
0022A: BTFSC @PRINTF_U_9600_31870_31871.P1.3
0022C: BRA 0244
0022E: BTFSS @PRINTF_U_9600_31870_31871.P1.0
00230: BRA 0244
00232: BTFSC @PRINTF_U_9600_31870_31871.P1.4
00234: MOVLW 20
00236: ADDWF @01,F
00238: MOVF @01,W
0023A: MOVLB E
0023C: BTFSS xCD.4
0023E: BRA 023C
00240: MOVWF TX1REG
00242: MOVLB 0
00244: MOVLW 30
00246: ADDWF ??65535,F
00248: MOVF ??65535,W
0024A: MOVLB E
0024C: BTFSS xCD.4
0024E: BRA 024C
00250: MOVWF TX1REG
00252: MOVLB 0
00254: RETURN 0
....................
.................... #list
....................
.................... #DEVICE ADC=10
....................
.................... #FUSES NOPPS1WAY
.................... #FUSES NOEXTOSC
.................... //#FUSES NOMCLR //MCLR on pull up and spst
.................... #FUSES NOBROWNOUT
.................... #FUSES NOLVP
.................... #FUSES NOWDT
.................... #FUSES NOPROTECT
.................... #FUSES PUT
.................... #USE delay(internal=64MHz)
*
00132: CLRF FSR0H
00134: MOVLW ??65535
00136: MOVWF FSR0L
00138: MOVF INDF0,W
0013A: BZ 0158
0013C: MOVLW 14
0013E: MOVWF @01
00140: CLRF @00
00142: DECFSZ @00,F
00144: BRA 0142
00146: DECFSZ @01,F
00148: BRA 0140
0014A: MOVLW BF
0014C: MOVWF @00
0014E: DECFSZ @00,F
00150: BRA 014E
00152: BRA 0154
00154: DECFSZ INDF0,F
00156: BRA 013C
00158: RETURN 0
.................... //=============================================================================
.................... // PIN SELECTS
.................... //=============================================================================
.................... #PIN_SELECT SCL1IN = PIN_C3
.................... #PIN_SELECT SCL1OUT = PIN_C3
.................... #PIN_SELECT SDA1IN = PIN_C4
.................... #PIN_SELECT SDA1OUT = PIN_C4
....................
.................... #PIN_SELECT SCL2IN = PIN_B1
.................... #PIN_SELECT SCL2OUT = PIN_B1
.................... #PIN_SELECT SDA2IN = PIN_B2
.................... #PIN_SELECT SDA2OUT = PIN_B2
....................
.................... #PIN_SELECT U1TX = PIN_C6
.................... #PIN_SELECT U1RX = PIN_C7
.................... //=============================================================================
.................... #USE RS232(UART1, BAUD=9600, PARITY=N, BITS=8, ERRORS, STREAM=COM)
.................... #USE I2C(I2C1, slave, address = 0xA0, STREAM=I2C)
....................
....................
....................
....................
....................
.................... char get_string[68];
....................
.................... int i2c_flag, i;
.................... int state[5];
.................... int data[5];
.................... ///////////////////////////////////////////////////////////////////////////////
.................... #int_SSP
.................... void SSP_ISR() {
.................... state[i] = i2c_isr_state(I2C);
*
000C0: CLRF @03
000C2: MOVF i,W
000C4: ADDLW state
000C6: MOVWF FSR0L
000C8: MOVLW state+-98
000CA: ADDWFC @03,W
000CC: MOVWF FSR0H
000CE: BTFSC SSP1STAT.A
000D0: BRA 00D8
000D2: CLRF @I2C_STATE
000D4: BTFSC SSP1STAT.W
000D6: BSF @I2C_STATE.7
000D8: MOVF @I2C_STATE,W
000DA: INCF @I2C_STATE,F
000DC: MOVWF INDF0
.................... data[i] = i2c_read(I2C,1);
000DE: CLRF @03
000E0: MOVF i,W
000E2: ADDLW data
000E4: MOVWF FSR0L
000E6: MOVLW data+-103
000E8: ADDWFC @03,W
000EA: MOVWF FSR0H
000EC: BCF SSP1CON1.SSPOV
000EE: BTFSS SSP1STAT.BF
000F0: BRA 00EE
000F2: MOVF SSP1BUF,W
000F4: BSF SSP1CON1.CKP
000F6: MOVWF INDF0
.................... i++;
000F8: INCF i,F
.................... i2c_flag++;
000FA: INCF i2c_flag,F
000FC: MOVLB E
000FE: BCF xCD.0
00100: MOVLB 0
00102: GOTO 006A
.................... }
.................... ///////////////////////////////////////////////////////////////////////////////
.................... void main() {
*
00256: BSF NVMCON1.NVMREG1
00258: BCF NVMCON1.NVMREG0
0025A: CLRF TBLPTRU
0025C: BCF T1GCON.GE
0025E: BSF 07.7
00260: MOVLB E
00262: MOVLW 55
00264: MOVWF xA0
00266: MOVLW AA
00268: MOVWF xA0
0026A: BCF xA0.0
0026C: MOVLW 17
0026E: MOVWF xB5
00270: MOVLW 13
00272: MOVWF xB7
00274: MOVLW 14
00276: MOVWF xB8
00278: MOVLW 09
0027A: MOVWF x8F
0027C: MOVLW 0A
0027E: MOVWF x90
00280: MOVLW 11
00282: MOVWF xF0
00284: MOVLW 12
00286: MOVWF xF1
00288: MOVLW 0F
0028A: MOVWF xFA
0028C: MOVLW 10
0028E: MOVWF xFB
00290: MOVLW 09
00292: MOVWF xFD
00294: MOVLW 55
00296: MOVWF xA0
00298: MOVLW AA
0029A: MOVWF xA0
0029C: BSF xA0.0
0029E: CLRF xDD
002A0: CLRF xDA
002A2: CLRF xDC
002A4: MOVLW 08
002A6: MOVWF xDE
002A8: MOVLW 60
002AA: MOVWF xD8
002AC: CLRF rs232_errors
002AE: BSF BAUD1CON.BRG16
002B0: MOVLW 82
002B2: MOVWF SP1BRGL
002B4: MOVLW 06
002B6: MOVWF SP1BRGH
002B8: MOVLW A6
002BA: MOVWF TX1STA
002BC: MOVLW 90
002BE: MOVWF RC1STA
002C0: BSF TRISC.3
002C2: BSF TRISC.4
002C4: MOVLW A0
002C6: MOVWF SSP1ADD
002C8: SETF SSP1MSK
002CA: MOVLW 36
002CC: MOVWF SSP1CON1
002CE: BSF SSP1CON2.SEN
002D0: BSF SSP1CON2.GCEN
002D2: MOVLW 03
002D4: MOVLB 0
002D6: MOVWF @I2C_STATE
002D8: CLRF @sprintf_string+1
002DA: CLRF @sprintf_string
002DC: MOVLB F
002DE: CLRF x11
002E0: CLRF x19
002E2: CLRF x21
002E4: CLRF x26
002E6: CLRF x2E
002E8: CLRF x3A
002EA: CLRF x3B
002EC: CLRF x3C
002EE: CLRF x39
002F0: CLRF x36
002F2: CLRF x37
002F4: CLRF x38
002F6: CLRF x35
.................... delay_ms(100);
002F8: MOVLW 64
002FA: MOVLB 0
002FC: MOVWF ??65535
002FE: RCALL 0132
.................... set_uart_speed(9600, COM);
00300: BSF BAUD1CON.BRG16
00302: MOVLW 82
00304: MOVWF SP1BRGL
00306: MOVLW 06
00308: MOVWF SP1BRGH
0030A: MOVLW A6
0030C: MOVWF TX1STA
0030E: MOVLW 90
00310: MOVWF RC1STA
.................... //--------------------------------------------------------------------------
.................... while (true) {
.................... fprintf(COM, "USER\r\n");
00312: MOVLW 06
00314: MOVWF TBLPTRL
00316: MOVLW 01
00318: MOVWF TBLPTRH
0031A: MOVLW 00
0031C: MOVWF TBLPTRU
0031E: BRA 015A
.................... for (i=0; i<5; i++) {
00320: CLRF i
00322: MOVF i,W
00324: SUBLW 04
00326: BNC 034C
.................... state[i] = 0;
00328: CLRF @03
0032A: MOVF i,W
0032C: ADDLW state
0032E: MOVWF FSR0L
00330: MOVLW state+-98
00332: ADDWFC @03,W
00334: MOVWF FSR0H
00336: CLRF INDF0
.................... data[i] = 0;
00338: CLRF @03
0033A: MOVF i,W
0033C: ADDLW data
0033E: MOVWF FSR0L
00340: MOVLW data+-103
00342: ADDWFC @03,W
00344: MOVWF FSR0H
00346: CLRF INDF0
00348: INCF i,F
0034A: BRA 0322
.................... }
.................... i2c_flag = 0;
0034C: CLRF i2c_flag
.................... i = 0;
0034E: CLRF i
.................... clear_interrupt(INT_SSP);
00350: MOVLB E
00352: BCF xCD.0
.................... enable_interrupts(INT_SSP);
00354: BSF xC5.0
.................... enable_interrupts(GLOBAL);
00356: MOVLW C0
00358: IORWF INTCON,F
.................... while (!i2c_flag) {
0035A: MOVLB 0
0035C: MOVF i2c_flag,F
0035E: BNZ 036A
.................... delay_us(1);
00360: MOVLW 05
00362: MOVWF @00
00364: DECFSZ @00,F
00366: BRA 0364
00368: BRA 035C
.................... }
.................... delay_ms(500);
0036A: MOVLW 02
0036C: MOVWF @@x6F
0036E: MOVLW FA
00370: MOVWF ??65535
00372: RCALL 0132
00374: DECFSZ @@x6F,F
00376: BRA 036E
.................... disable_interrupts(GLOBAL);
00378: BCF INTCON.GIEL
0037A: BCF INTCON.GIEH
0037C: BTFSC INTCON.GIEH
0037E: BRA 037A
.................... disable_interrupts(INT_SSP);
00380: MOVLB E
00382: BCF xC5.0
.................... for (i=0; i < 5; i++) {
00384: MOVLB 0
00386: CLRF i
00388: MOVF i,W
0038A: SUBLW 04
0038C: BNC 044E
.................... fprintf(COM, "state[%u] = %u\r\n", i, state[i]);
0038E: CLRF @03
00390: MOVF i,W
00392: ADDLW state
00394: MOVWF FSR0L
00396: MOVLW state+-98
00398: ADDWFC @03,W
0039A: MOVWF FSR0H
0039C: MOVFF INDF0,@@6F
003A0: MOVLW 0E
003A2: MOVWF TBLPTRL
003A4: MOVLW 01
003A6: MOVWF TBLPTRH
003A8: MOVLW 00
003AA: MOVWF TBLPTRU
003AC: MOVLW 06
003AE: MOVWF ??65535
003B0: RCALL 018A
003B2: MOVFF i,??65535
003B6: MOVLW 1B
003B8: MOVWF @PRINTF_U_9600_31870_31871.P1
003BA: RCALL 01DE
003BC: MOVLW 16
003BE: MOVWF TBLPTRL
003C0: MOVLW 01
003C2: MOVWF TBLPTRH
003C4: MOVLW 00
003C6: MOVWF TBLPTRU
003C8: MOVLW 04
003CA: MOVWF ??65535
003CC: RCALL 018A
003CE: MOVFF @@6F,??65535
003D2: MOVLW 1B
003D4: MOVWF @PRINTF_U_9600_31870_31871.P1
003D6: RCALL 01DE
003D8: MOVLW 0D
003DA: MOVLB E
003DC: BTFSS xCD.4
003DE: BRA 03DC
003E0: MOVWF TX1REG
003E2: MOVLW 0A
003E4: BTFSS xCD.4
003E6: BRA 03E4
003E8: MOVWF TX1REG
.................... fprintf(COM, "data[%u] = %u\r\n", i, data[i]);
003EA: CLRF @03
003EC: MOVLB 0
003EE: MOVF i,W
003F0: ADDLW data
003F2: MOVWF FSR0L
003F4: MOVLW data+-103
003F6: ADDWFC @03,W
003F8: MOVWF FSR0H
003FA: MOVFF INDF0,@@6F
003FE: MOVLW 20
00400: MOVWF TBLPTRL
00402: MOVLW 01
00404: MOVWF TBLPTRH
00406: MOVLW 00
00408: MOVWF TBLPTRU
0040A: MOVLW 05
0040C: MOVWF ??65535
0040E: RCALL 018A
00410: MOVFF i,??65535
00414: MOVLW 1B
00416: MOVWF @PRINTF_U_9600_31870_31871.P1
00418: RCALL 01DE
0041A: MOVLW 27
0041C: MOVWF TBLPTRL
0041E: MOVLW 01
00420: MOVWF TBLPTRH
00422: MOVLW 00
00424: MOVWF TBLPTRU
00426: MOVLW 05
00428: MOVWF ??65535
0042A: RCALL 018A
0042C: MOVFF @@6F,??65535
00430: MOVLW 1B
00432: MOVWF @PRINTF_U_9600_31870_31871.P1
00434: RCALL 01DE
00436: MOVLW 0D
00438: MOVLB E
0043A: BTFSS xCD.4
0043C: BRA 043A
0043E: MOVWF TX1REG
00440: MOVLW 0A
00442: BTFSS xCD.4
00444: BRA 0442
00446: MOVWF TX1REG
00448: MOVLB 0
0044A: INCF i,F
0044C: BRA 0388
.................... }
0044E: BRA 0312
.................... }
.................... }
....................
00450: SLEEP
....................
....................
....................
Configuration Fuses:
Word 1: 2904 NOEXTOSC RSTOSC_HFINTRC_64MHZ NOCLKOUT CKS FCMEN
Word 2: B721 MCLR PUT NOLPBOR NOBROWNOUT BORV24 ZCDDIS NOPPS1WAY STVREN NODEBUG NOXINST
Word 3: 3F1F WDTSW NOWDT WDTWIN_SW WDTCLK_SW
Word 4: 17FF NOWRT NOWRTC NOWRTB NOWRTD SCANE NOLVP
Word 5: 0003 NOPROTECT NOCPD
Word 6: 02FF NOEBTR NOEBTRB
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19480
|
|
Posted: Fri Jan 13, 2017 2:29 am |
|
|
Look at the examples.....
Your I2C_ISR is 'missing the point a little'.
The interrupt will occur when the address byte is received as well as data, so you need to use the value from the I2C_ISR_STATE to determine what the slave is actually to do, and reset the 'i' counter.
Without this, data written to the array _will_ eventually risk overflowing, and this will then overwrite the other variables. Result 'disaster'.... |
|
|
mob1182
Joined: 03 Mar 2016 Posts: 28
|
|
Posted: Fri Jan 13, 2017 6:45 am |
|
|
Thanks Ttelmah, but what I'm trying to say is that the state of the ISR is always 0, even if I change the r/w bit in the address the master is sending for a read instead of a write. I never get 0x80, or 1, or 2... and believe me I looked at the examples and datasheets over and over before I came here. I've read sec 26.9.2.1 on the pic datasheet so I understand it interrupts after an address match and every byte of data. That's why I have the 500ms delay, to allow all the data to come in. And this is just a test program to read the state value and data. The final version will a lot different, more like the ccs example. And the "i" variable does get reset in the while(true) loop. I am currently controlling the data being sent so for know it is only a few bytes to not overflow the array. When I broadcast a command in teraterm, it gets saved to pKeyword[1] and send to the slave. So im personally keeping it to only a few bytes. But maybe I am missing the point a little, and I'm still missing it lol. Obviously I'm doing something wrong cause it doesn't work |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19480
|
|
Posted: Fri Jan 13, 2017 6:54 am |
|
|
Your master needs to send the last byte in the transaction with a NACK. This marks the end of transaction (not actually the stop).
In the 'long' transaction, the slave is looping with the I2C in an error state (since the transaction has not correctly terminated), and overwriting the state bytes, so you just see zero). |
|
|
mob1182
Joined: 03 Mar 2016 Posts: 28
|
|
Posted: Fri Jan 13, 2017 7:57 am |
|
|
Ok I'm just a little confused. I thought that was only for a slave transmission to the master? To indicate to the master that the slave is done. Not for the master to tell the slave its done.
This is a slave reception. I don't see this in the i2c spec anywhere. Nor in the pic datasheet in 26.9.2.1 for slave reception or 26.10.6.3 for master transmission. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19480
|
|
Posted: Fri Jan 13, 2017 8:40 am |
|
|
Apologies it is your slave that has the problem here.
The point is you may well have another problem, but lets get your code tidy, and workable to see. You only needed to post about ten lines for the transmit side, and twenty for the receive, instead we have a huge amount that is much too complex.
You are _forcing_ an ACK on everything in the slave, but the hardware handles the ACK/NACK for the slave. Forcing it will cause problems. |
|
|
mob1182
Joined: 03 Mar 2016 Posts: 28
|
|
Posted: Fri Jan 13, 2017 10:16 am |
|
|
Ok so take the "1" argument out of i2c_read()?
To simplify I removed that from the read and the stream argument since its the only i2c stream.
Still having the same problem
Now this works. When I send the characters "12" from the master I get 0,1,2 for the state array and 160,49,50 for the data array, which is correct. address A0 = 160, acii 1 = 49 and acii 2 = 50.
Code: |
#include "main.h"
char get_string[65]; ////works with this at 65 but not 68
int i2c_flag, i;
int state[5];
int data[5];
#int_SSP
void SSP_ISR() {
state[i] = i2c_isr_state();
data[i] = i2c_read();
i++;
i2c_flag++;
}
void main() {
delay_ms(100);
set_uart_speed(9600, COM);
while (true) {
fprintf(COM, "USER\r\n");
//--------------------------
for (i=0; i<5; i++) { //reset arrays
state[i] = 0;
data[i] = 0;
}
i2c_flag = 0; //reset flag
i = 0; //reset i
//--------------------------
clear_interrupt(INT_SSP);
enable_interrupts(INT_SSP);
enable_interrupts(GLOBAL);
while (!i2c_flag) { //wait til data is sent
delay_us(1);
}
delay_ms(500); //once addr is rcvd give time for rest of data
disable_interrupts(GLOBAL);
disable_interrupts(INT_SSP);
for (i=0; i < 5; i++) { //print arrays
fprintf(COM, "state[%u] = %u\r\n", i, state[i]);
fprintf(COM, "data[%u] = %u\r\n", i, data[i]);
}
}
}
|
Now if I change get_string to a larger array it doesn't work, and get_string is not even being used yet.
Actually if I change the get_string array to 67 I get all 0's for the state and data array. And...
If I change it to 68, or larger, the interrupt doesn't even seem to fire cause the code does not continue, indicating that i2c_flag is not being set. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19480
|
|
Posted: Fri Jan 13, 2017 10:34 am |
|
|
OK. Now we have something small enough to look at.
There was a very similar thread a few weeks ago, and another that may relate:
<http://www.ccsinfo.com/forum/viewtopic.php?t=55779>
So, what programmer are you using?.
The other was actually using a bootloader, and this was not setup correctly and causing a problem as soon as an array went over a certain size. |
|
|
mob1182
Joined: 03 Mar 2016 Posts: 28
|
|
Posted: Fri Jan 13, 2017 10:44 am |
|
|
Ha yea that link is my post too from before Christmas. So I can't get the icd-u64 programmer to program correctly for this particular chip. I've used it just fine for other older chips. This chip is fairly new. Came out middle of last year I believe(could be wrong, dnt hold me to that).
I put a support ticket into CCS about it but never heard anything back. Even though I paid the $250 maintenance fee to upgrade my compiler just to support this chip.
What I'm currently doing is using CCS to create the hex file after compile. Then importing that hex into mplabs integrated programming environment app. And using a pickit 3 to program. I am getting programs greater than 640 instruction to program and verify doing this. |
|
|
mob1182
Joined: 03 Mar 2016 Posts: 28
|
|
Posted: Mon Jan 16, 2017 9:15 am |
|
|
I just used a different programmer, a softlog ICP2, and got the same results. So I don't think this is a programming issue. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19480
|
|
Posted: Mon Jan 16, 2017 9:53 am |
|
|
OK. I'll see if I can try some programs on your chip and see what is happening. Unfortunately been having problems with my Windows (so with being able to run CCS). Turns out to be with Parallels (which is how I run Windows most of the time, since I use Macintoshes), have had to go back a few versions on this, and have Windows working again OK now, but have lost a lot of time, so it may be a while before I can 'catch up'. |
|
|
mob1182
Joined: 03 Mar 2016 Posts: 28
|
|
Posted: Mon Jan 16, 2017 12:19 pm |
|
|
Problem with windows! Ha never lol. I do appreciate you taking the time in helping me for what its worth.
Just an update, I simplified the code even more. Made the state and data arrays just a int variable. commented out the i2c_isr_state(), all I want is to see if i can get 1 byte of data and continue. Took out "i". "for" loops and stuff. Only thing im sending is the address byte. Again works with get_string array at 65 but not 68.
This is the interesting part. I notice that the SDA line returns to 5V after the address byte is sent. So the slave is sending an ack I assume. If I comment out the i2c_read() and reprogram, the SDA line remains low, so no stop being sent cause its not getting an ACK.
So it appears that the interrupt is firing but the data does not get saved correctly and the i2c_flag value too. Now I don't know assembly language (this is why I use CCS) so it's hard for me to figure out exactly what's going on
Here is the code
Code: |
#include "main.h"
char get_string[68];
int i2c_flag;
int data = 0;
#int_SSP
void SSP_ISR() {
data = i2c_read();
i2c_flag = 1;
}
void main() {
delay_ms(100);
set_uart_speed(9600, COM);
while (true) {
fprintf(COM, "USER\r\n");
i2c_flag = 0; //reset flag
//--------------------------
clear_interrupt(INT_SSP);
enable_interrupts(INT_SSP);
enable_interrupts(GLOBAL);
while (!i2c_flag) { //wait til data is sent
delay_us(1);
}
fprintf(COM, "data = %u\r\n", data);
}
}
|
Assembly
Code: |
00000 EF0D F001 00001 GOTO 021A
00008 6E04 00002 MOVWF 04
0000A CFD8 F005 00003 MOVFF FD8,05
0000E CFE0 F006 00004 MOVFF FE0,06
00012 0100 00005 MOVLB 0
00014 CFE9 F00C 00006 MOVFF FE9,0C
00018 CFEA F007 00007 MOVFF FEA,07
0001C CFE1 F008 00008 MOVFF FE1,08
00020 CFE2 F009 00009 MOVFF FE2,09
00024 CFD9 F00A 00010 MOVFF FD9,0A
00028 CFDA F00B 00011 MOVFF FDA,0B
0002C CFF3 F012 00012 MOVFF FF3,12
00030 CFF4 F013 00013 MOVFF FF4,13
00034 CFFA F014 00014 MOVFF FFA,14
00038 CFF5 F015 00015 MOVFF FF5,15
0003C CFF6 F016 00016 MOVFF FF6,16
00040 CFF7 F017 00017 MOVFF FF7,17
00044 CFF8 F018 00018 MOVFF FF8,18
00048 CFFB F019 00019 MOVFF FFB,19
0004C C000 F00E 00020 MOVFF 00,0E
00050 C001 F00F 00021 MOVFF 01,0F
00054 C002 F010 00022 MOVFF 02,10
00058 C003 F011 00023 MOVFF 03,11
0005C 010E 00024 MOVLB E
0005E A1C5 00025 BTFSS xC5.0
00060 EF35 F000 00026 GOTO 006A
00064 B1CD 00027 BTFSC xCD.0
00066 EF60 F000 00028 GOTO 00C0
0006A C00E F000 00029 MOVFF 0E,00
0006E C00F F001 00030 MOVFF 0F,01
00072 C010 F002 00031 MOVFF 10,02
00076 C011 F003 00032 MOVFF 11,03
0007A C00C FFE9 00033 MOVFF 0C,FE9
0007E C007 FFEA 00034 MOVFF 07,FEA
00082 8E07 00035 BSF 07.7
00084 C008 FFE1 00036 MOVFF 08,FE1
00088 C009 FFE2 00037 MOVFF 09,FE2
0008C C00A FFD9 00038 MOVFF 0A,FD9
00090 C00B FFDA 00039 MOVFF 0B,FDA
00094 C012 FFF3 00040 MOVFF 12,FF3
00098 C013 FFF4 00041 MOVFF 13,FF4
0009C C014 FFFA 00042 MOVFF 14,FFA
000A0 C015 FFF5 00043 MOVFF 15,FF5
000A4 C016 FFF6 00044 MOVFF 16,FF6
000A8 C017 FFF7 00045 MOVFF 17,FF7
000AC C018 FFF8 00046 MOVFF 18,FF8
000B0 C019 FFFB 00047 MOVFF 19,FFB
000B4 5004 00048 MOVF 04,W
000B6 C006 FFE0 00049 MOVFF 06,FE0
000BA C005 FFD8 00050 MOVFF 05,FD8
000BE 0010 00051 RETFIE 0
00052 .................... #include "main.h"
00053 .................... #include <18F47K40.h>
00054 .................... //////////// Standard Header file for the PIC18F47K40 device ////////////////
00055 .................... ///////////////////////////////////////////////////////////////////////////
00056 .................... //// (C) Copyright 1996, 2014 Custom Computer Services ////
00057 .................... //// This source code may only be used by licensed users of the CCS C ////
00058 .................... //// compiler. This source code may only be distributed to other ////
00059 .................... //// licensed users of the CCS C compiler. No other use, reproduction ////
00060 .................... //// or distribution is permitted without written permission. ////
00061 .................... //// Derivative programs created using this software in object code ////
00062 .................... //// form are not restricted in any way. ////
00063 .................... ///////////////////////////////////////////////////////////////////////////
00064 .................... #device PIC18F47K40
000DA 5355 00065 DATA 55,53
000DC 5245 00066 DATA 45,52
000DE 0A0D 00067 DATA 0D,0A
000E0 0000 00068 DATA 00,00
000E2 6164 00069 DATA 64,61
000E4 6174 00070 DATA 74,61
000E6 2020 00071 DATA 20,20
000E8 203D 00072 DATA 3D,20
000EA 7525 00073 DATA 25,75
000EC 0A0D 00074 DATA 0D,0A
000EE 0000 00075 DATA 00,00
0011A 0009 00076 TBLRD*+
0011C 52F5 00077 MOVF FF5,F
0011E E013 00078 BZ 0146
00120 CFF6 F064 00079 MOVFF FF6,64
00124 CFF7 F065 00080 MOVFF FF7,65
00128 CFF8 F066 00081 MOVFF FF8,66
0012C 50F5 00082 MOVF FF5,W
0012E 010E 00083 MOVLB E
00130 A9CD 00084 BTFSS xCD.4
00132 D7FE 00085 BRA 0130
00134 6E9A 00086 MOVWF F9A
00136 C064 FFF6 00087 MOVFF 64,FF6
0013A C065 FFF7 00088 MOVFF 65,FF7
0013E C066 FFF8 00089 MOVFF 66,FF8
00142 0100 00090 MOVLB 0
00144 D7EA 00091 BRA 011A
00146 EF69 F001 00092 GOTO 02D2 (RETURN)
0014A 0009 00093 TBLRD*+
0014C CFF6 F065 00094 MOVFF FF6,65
00150 CFF7 F066 00095 MOVFF FF7,66
00154 CFF8 F067 00096 MOVFF FF8,67
00158 50F5 00097 MOVF FF5,W
0015A 010E 00098 MOVLB E
0015C A9CD 00099 BTFSS xCD.4
0015E D7FE 00100 BRA 015C
00160 6E9A 00101 MOVWF F9A
00162 C065 FFF6 00102 MOVFF 65,FF6
00166 C066 FFF7 00103 MOVFF 66,FF7
0016A C067 FFF8 00104 MOVFF 67,FF8
0016E 0100 00105 MOVLB 0
00170 2F64 00106 DECFSZ x64,F
00172 D7EB 00107 BRA 014A
00174 EF80 F001 00108 GOTO 0300 (RETURN)
00178 5167 00109 MOVF x67,W
0017A 6A01 00110 CLRF 01
0017C 5D66 00111 SUBWF x66,W
0017E E203 00112 BC 0186
00180 C066 F000 00113 MOVFF 66,00
00184 D00C 00114 BRA 019E
00186 6A00 00115 CLRF 00
00188 0E08 00116 MOVLW 08
0018A 6F68 00117 MOVWF x68
0018C 3766 00118 RLCF x66,F
0018E 3600 00119 RLCF 00,F
00190 5167 00120 MOVF x67,W
00192 5C00 00121 SUBWF 00,W
00194 B0D8 00122 BTFSC FD8.0
00196 6E00 00123 MOVWF 00
00198 3601 00124 RLCF 01,F
0019A 2F68 00125 DECFSZ x68,F
0019C D7F7 00126 BRA 018C
0019E 0012 00127 RETURN 0
001A0 5001 00128 MOVF 01,W
001A2 C064 F066 00129 MOVFF 64,66
001A6 0E64 00130 MOVLW 64
001A8 6F67 00131 MOVWF x67
001AA DFE6 00132 RCALL 0178
001AC C000 F064 00133 MOVFF 00,64
001B0 5001 00134 MOVF 01,W
001B2 0E30 00135 MOVLW 30
001B4 E107 00136 BNZ 01C4
001B6 A365 00137 BTFSS x65.1
001B8 D00F 00138 BRA 01D8
001BA B765 00139 BTFSC x65.3
001BC D00D 00140 BRA 01D8
001BE B965 00141 BTFSC x65.4
001C0 0E20 00142 MOVLW 20
001C2 D003 00143 BRA 01CA
001C4 9765 00144 BCF x65.3
001C6 9965 00145 BCF x65.4
001C8 8165 00146 BSF x65.0
001CA 2601 00147 ADDWF 01,F
001CC 5001 00148 MOVF 01,W
001CE 010E 00149 MOVLB E
001D0 A9CD 00150 BTFSS xCD.4
001D2 D7FE 00151 BRA 01D0
001D4 6E9A 00152 MOVWF F9A
001D6 0100 00153 MOVLB 0
001D8 C064 F066 00154 MOVFF 64,66
001DC 0E0A 00155 MOVLW 0A
001DE 6F67 00156 MOVWF x67
001E0 DFCB 00157 RCALL 0178
001E2 C000 F064 00158 MOVFF 00,64
001E6 5001 00159 MOVF 01,W
001E8 0E30 00160 MOVLW 30
001EA E106 00161 BNZ 01F8
001EC B765 00162 BTFSC x65.3
001EE D00B 00163 BRA 0206
001F0 A165 00164 BTFSS x65.0
001F2 D009 00165 BRA 0206
001F4 B965 00166 BTFSC x65.4
001F6 0E20 00167 MOVLW 20
001F8 2601 00168 ADDWF 01,F
001FA 5001 00169 MOVF 01,W
001FC 010E 00170 MOVLB E
001FE A9CD 00171 BTFSS xCD.4
00200 D7FE 00172 BRA 01FE
00202 6E9A 00173 MOVWF F9A
00204 0100 00174 MOVLB 0
00206 0E30 00175 MOVLW 30
00208 2764 00176 ADDWF x64,F
0020A 5164 00177 MOVF x64,W
0020C 010E 00178 MOVLB E
0020E A9CD 00179 BTFSS xCD.4
00210 D7FE 00180 BRA 020E
00212 6E9A 00181 MOVWF F9A
00214 0100 00182 MOVLB 0
00216 EF85 F001 00183 GOTO 030A (RETURN)
00184 ....................
01853 .................... #list
01854 ....................
01855 .................... #DEVICE ADC=10
01856 ....................
01857 .................... #FUSES NOPPS1WAY
01858 .................... #FUSES NOEXTOSC
01859 .................... //#FUSES NOMCLR //MCLR on pull up and spst
01860 .................... #FUSES NOBROWNOUT
01861 .................... #FUSES NOLVP
01862 .................... #FUSES NOWDT
01863 .................... #FUSES NOPROTECT
01864 .................... #FUSES PUT
01865 .................... #USE delay(internal=64MHz)
000F0 6AEA 01866 CLRF FEA
000F2 0E64 01867 MOVLW 64
000F4 6EE9 01868 MOVWF FE9
000F6 50EF 01869 MOVF FEF,W
000F8 E00E 01870 BZ 0116
000FA 0E14 01871 MOVLW 14
000FC 6E01 01872 MOVWF 01
000FE 6A00 01873 CLRF 00
00100 2E00 01874 DECFSZ 00,F
00102 D7FE 01875 BRA 0100
00104 2E01 01876 DECFSZ 01,F
00106 D7FB 01877 BRA 00FE
00108 0EBF 01878 MOVLW BF
0010A 6E00 01879 MOVWF 00
0010C 2E00 01880 DECFSZ 00,F
0010E D7FE 01881 BRA 010C
00110 D000 01882 BRA 0112
00112 2EEF 01883 DECFSZ FEF,F
00114 D7F2 01884 BRA 00FA
00116 EF59 F001 01885 GOTO 02B2 (RETURN)
01886 .................... //=============================================================================
01887 .................... // PIN SELECTS
01888 .................... //=============================================================================
01889 .................... #PIN_SELECT SCL1IN = PIN_C3
01890 .................... #PIN_SELECT SCL1OUT = PIN_C3
01891 .................... #PIN_SELECT SDA1IN = PIN_C4
01892 .................... #PIN_SELECT SDA1OUT = PIN_C4
01893 ....................
01894 .................... #PIN_SELECT U1TX = PIN_C6
01895 .................... #PIN_SELECT U1RX = PIN_C7
01896 .................... //=============================================================================
01897 .................... #USE RS232(UART1, BAUD=9600, PARITY=N, BITS=8, ERRORS, STREAM=COM)
01898 .................... #USE I2C(I2C1, slave, address = 0xA0)
01899 ....................
01900 ....................
01901 ....................
01902 ....................
01903 ....................
01904 .................... char get_string[68];
01905 .................... int i2c_flag;
01906 .................... int data = 0;
01907 .................... #int_SSP
01908 .................... void SSP_ISR() {
01909 .................... data = i2c_read();
000C0 9C96 01910 BCF F96.6
000C2 A095 01911 BTFSS F95.0
000C4 D7FE 01912 BRA 00C2
000C6 5092 01913 MOVF F92,W
000C8 8896 01914 BSF F96.4
000CA 6F61 01915 MOVWF x61
01916 .................... i2c_flag = 1;
000CC 0E01 01917 MOVLW 01
000CE 6F60 01918 MOVWF x60
000D0 010E 01919 MOVLB E
000D2 91CD 01920 BCF xCD.0
000D4 0100 01921 MOVLB 0
000D6 EF35 F000 01922 GOTO 006A
01923 .................... }
01924 .................... void main() {
0021A 8E81 01925 BSF F81.7
0021C 9C81 01926 BCF F81.6
0021E 6AF8 01927 CLRF FF8
00220 9ED0 01928 BCF FD0.7
00222 8E07 01929 BSF 07.7
00224 010E 01930 MOVLB E
00226 0E55 01931 MOVLW 55
00228 6FA0 01932 MOVWF xA0
0022A 0EAA 01933 MOVLW AA
0022C 6FA0 01934 MOVWF xA0
0022E 91A0 01935 BCF xA0.0
00230 0E17 01936 MOVLW 17
00232 6FB5 01937 MOVWF xB5
00234 0E13 01938 MOVLW 13
00236 6FB7 01939 MOVWF xB7
00238 0E14 01940 MOVLW 14
0023A 6FB8 01941 MOVWF xB8
0023C 0E0F 01942 MOVLW 0F
0023E 6FFA 01943 MOVWF xFA
00240 0E10 01944 MOVLW 10
00242 6FFB 01945 MOVWF xFB
00244 0E09 01946 MOVLW 09
00246 6FFD 01947 MOVWF xFD
00248 0E55 01948 MOVLW 55
0024A 6FA0 01949 MOVWF xA0
0024C 0EAA 01950 MOVLW AA
0024E 6FA0 01951 MOVWF xA0
00250 81A0 01952 BSF xA0.0
00252 6BDD 01953 CLRF xDD
00254 6BDA 01954 CLRF xDA
00256 6BDC 01955 CLRF xDC
00258 0E08 01956 MOVLW 08
0025A 6FDE 01957 MOVWF xDE
0025C 0E60 01958 MOVLW 60
0025E 6FD8 01959 MOVWF xD8
00260 6A1B 01960 CLRF 1B
00262 869F 01961 BSF F9F.3
00264 0E82 01962 MOVLW 82
00266 6E9B 01963 MOVWF F9B
00268 0E06 01964 MOVLW 06
0026A 6E9C 01965 MOVWF F9C
0026C 0EA6 01966 MOVLW A6
0026E 6E9E 01967 MOVWF F9E
00270 0E90 01968 MOVLW 90
00272 6E9D 01969 MOVWF F9D
00274 868A 01970 BSF F8A.3
00276 888A 01971 BSF F8A.4
00278 0EA0 01972 MOVLW A0
0027A 6E93 01973 MOVWF F93
0027C 6894 01974 SETF F94
0027E 0E36 01975 MOVLW 36
00280 6E96 01976 MOVWF F96
00282 8097 01977 BSF F97.0
00284 8E97 01978 BSF F97.7
00286 0100 01979 MOVLB 0
00288 6B61 01980 CLRF x61
0028A 6B63 01981 CLRF x63
0028C 6B62 01982 CLRF x62
0028E 010F 01983 MOVLB F
00290 6B11 01984 CLRF x11
00292 6B19 01985 CLRF x19
00294 6B21 01986 CLRF x21
00296 6B26 01987 CLRF x26
00298 6B2E 01988 CLRF x2E
0029A 6B3A 01989 CLRF x3A
0029C 6B3B 01990 CLRF x3B
0029E 6B3C 01991 CLRF x3C
002A0 6B39 01992 CLRF x39
002A2 6B36 01993 CLRF x36
002A4 6B37 01994 CLRF x37
002A6 6B38 01995 CLRF x38
002A8 6B35 01996 CLRF x35
01997 .................... delay_ms(100);
002AA 0E64 01998 MOVLW 64
002AC 0100 01999 MOVLB 0
002AE 6F64 02000 MOVWF x64
002B0 D71F 02001 BRA 00F0
02002 .................... set_uart_speed(9600, COM);
002B2 869F 02003 BSF F9F.3
002B4 0E82 02004 MOVLW 82
002B6 6E9B 02005 MOVWF F9B
002B8 0E06 02006 MOVLW 06
002BA 6E9C 02007 MOVWF F9C
002BC 0EA6 02008 MOVLW A6
002BE 6E9E 02009 MOVWF F9E
002C0 0E90 02010 MOVLW 90
002C2 6E9D 02011 MOVWF F9D
02012 .................... while (true) {
02013 .................... fprintf(COM, "USER\r\n");
002C4 0EDA 02014 MOVLW DA
002C6 6EF6 02015 MOVWF FF6
002C8 0E00 02016 MOVLW 00
002CA 6EF7 02017 MOVWF FF7
002CC 0E00 02018 MOVLW 00
002CE 6EF8 02019 MOVWF FF8
002D0 D724 02020 BRA 011A
02021 .................... i2c_flag = 0; //reset flag
002D2 6B60 02022 CLRF x60
02023 .................... //--------------------------
02024 .................... clear_interrupt(INT_SSP);
002D4 010E 02025 MOVLB E
002D6 91CD 02026 BCF xCD.0
02027 .................... enable_interrupts(INT_SSP);
002D8 81C5 02028 BSF xC5.0
02029 .................... enable_interrupts(GLOBAL);
002DA 0EC0 02030 MOVLW C0
002DC 12F2 02031 IORWF FF2,F
02032 .................... while (!i2c_flag) { //wait til data is sent
002DE 0100 02033 MOVLB 0
002E0 5360 02034 MOVF x60,F
002E2 E105 02035 BNZ 02EE
02036 .................... delay_us(1);
002E4 0E05 02037 MOVLW 05
002E6 6E00 02038 MOVWF 00
002E8 2E00 02039 DECFSZ 00,F
002EA D7FE 02040 BRA 02E8
002EC D7F9 02041 BRA 02E0
02042 .................... }
02043 .................... fprintf(COM, "data = %u\r\n", data);
002EE 0EE2 02044 MOVLW E2
002F0 6EF6 02045 MOVWF FF6
002F2 0E00 02046 MOVLW 00
002F4 6EF7 02047 MOVWF FF7
002F6 0E00 02048 MOVLW 00
002F8 6EF8 02049 MOVWF FF8
002FA 0E08 02050 MOVLW 08
002FC 6F64 02051 MOVWF x64
002FE D725 02052 BRA 014A
00300 C061 F064 02053 MOVFF 61,64
00304 0E1B 02054 MOVLW 1B
00306 6F65 02055 MOVWF x65
00308 D74B 02056 BRA 01A0
0030A 0E0D 02057 MOVLW 0D
0030C 010E 02058 MOVLB E
0030E A9CD 02059 BTFSS xCD.4
00310 D7FE 02060 BRA 030E
00312 6E9A 02061 MOVWF F9A
00314 0E0A 02062 MOVLW 0A
00316 A9CD 02063 BTFSS xCD.4
00318 D7FE 02064 BRA 0316
0031A 6E9A 02065 MOVWF F9A
0031C 0100 02066 MOVLB 0
0031E D7D2 02067 BRA 02C4
02068 .................... }
02069 .................... }
02070 ....................
00320 0003 02071 SLEEP
02072 ....................
02073 ....................
02074 ....................
Configuration Fuses:
Word 1: 2904 NOEXTOSC RSTOSC_HFINTRC_64MHZ NOCLKOUT CKS FCMEN
Word 2: B721 MCLR PUT NOLPBOR NOBROWNOUT BORV24 ZCDDIS NOPPS1WAY STVREN NODEBUG NOXINST
Word 3: 3F1F WDTSW NOWDT WDTWIN_SW WDTCLK_SW
Word 4: 17FF NOWRT NOWRTC NOWRTB NOWRTD SCANE NOLVP
Word 5: 0003 NOPROTECT NOCPD
Word 6: 02FF NOEBTR NOEBTRB
SYMBOL TABLE
LABEL VALUE
_RETURN_ 00000001
rs232_errors 0000001B
get_string 0000001C
i2c_flag 00000060
data 00000061
LVDRDY 00000F2F
LVDOUT 00000F2F
C2OUT 00000F35
C1OUT 00000F39
MDBIT 00000F51
MDOUT 00000F51
ADACLR 00000F5A
PWM4OUT 00000FA2
PWM3OUT 00000FA5
CCP_2_LOW 00000FA9
CCP_2 00000FA9
CCP_2_HIGH 00000FAA
CCP_1_LOW 00000FAD
CCP_1 00000FAD
CCP_1_HIGH 00000FAE
Allocation: 0000EEEF
SSP_ISR 00000000
MAIN 00000002
MEMORY USAGE
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19480
|
|
Posted: Mon Jan 16, 2017 1:42 pm |
|
|
The hardware actually releases the clock, when the byte is read.
Now on some chips there has been a problem in the past with this having to be done manually (setting up a CKP bit and setting this at the end of the interrupt handler).
I notice the chip has a really nasty erratum about TBLRD operations. Will have to look and see if CCS are handling this.
What happens if you define the array after the other variables?. |
|
|
mob1182
Joined: 03 Mar 2016 Posts: 28
|
|
Posted: Mon Jan 16, 2017 2:25 pm |
|
|
Wow ok so if I define the array after the other variables it does work.
So this is a chip error then and not the CCS compiler?
And it looks like this only effects rev A2 chips, which is what I have. I wonder if there is anyway to request rev A3 when ordering.
I don't completely know how this will affect the code once I grow it, but hopefully I can work around this now that I know what the issue is, somewhat anyway.
Thanks Ttelmah! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jan 16, 2017 2:46 pm |
|
|
Quote: | if I define the array after the other variables it does work |
In your original code, when you increase the size of the array, you are
moving the variables 'data' and 'i2c_flag' out of Access Ram (0x00 to 0x5F),
and into regular banked Ram. This could be a clue. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|