|
|
View previous topic :: View next topic |
Author |
Message |
cgperalta
Joined: 14 Mar 2005 Posts: 4
|
I2C Force_HW doesn't work... |
Posted: Mon Mar 14, 2005 2:54 pm |
|
|
I'm trying to compile a code using force_hw in #use i2c staement, but when I see the list, it's clearly seen that is using software routines to read the I2C Bus. I'm using 16F819 and PCM 3.216.
The same code, compiled with an earlier version of PCM works as it should.... using hardware.
All I've changed is the compiler version.
Any help would be appreciatted.
Thank you. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Mar 14, 2005 3:05 pm |
|
|
Post a very simple, but complete program that shows the problem.
What we will do, is to drop your program into MPLAB and try
to duplicate the problem. Don't leave anything out. Post #fuses,
#includes, #use statements, and your code, etc., but keep it short. |
|
|
cgperalta
Joined: 14 Mar 2005 Posts: 4
|
|
Posted: Wed Mar 16, 2005 6:45 am |
|
|
This is a very simple sample code, and it doesn't work either...
#include <16F818.h> //CCS Header file
#include <pic16f818.h> //My header file, hardware registers
#device adc=10
#use delay(clock=8000000,RESTART_WDT)
#fuses INTRC_IO,PUT,BROWNOUT,WDT,NOLVP,NODEBUG,MCLR,NOWRT,CCPB2,NOPROTECT
#use i2c(Slave, fast, sda=PIN_B1, scl=PIN_B4, force_hw, address=0x01)
void main() {
char a;
osccon = 0x70; // Setea el oscilador a 8MHz
while(!IOFS){} // Espera a que el reloj est� estable.
a= i2c_read();
}
It generates this assembly...
.................... #device adc=10
.................... #use delay(clock=8000000,RESTART_WDT)
.................... #fuses INTRC_IO,PUT,BROWNOUT,WDT,NOLVP,NODEBUG,MCLR,NOWRT,CCPB2,NOPROTECT
.................... #use i2c(Slave, fast, sda=PIN_B1, scl=PIN_B4, force_hw, address=0x01)
0004: MOVLW 08
0005: MOVWF @@23
0006: BSF STATUS.5
0007: BSF TRISB.4
0008: BSF TRISB.1
0009: BCF STATUS.5
000A: BTFSS PORTB.4
000B: GOTO 00E
000C: BSF STATUS.5
000D: GOTO 009
000E: BTFSS PORTB.4
000F: GOTO 00E
0010: BTFSC PORTB.1
0011: BSF STATUS.0
0012: BTFSS PORTB.1
0013: BCF STATUS.0
0014: RLF @78,F
0015: DECFSZ @@23,F
0016: GOTO 018
0017: GOTO 01A
0018: BSF STATUS.5
0019: GOTO 009
001A: BTFSC PORTB.4
001B: GOTO 01A
001C: BSF STATUS.5
001D: BCF TRISB.1
001E: BCF STATUS.5
001F: BCF PORTB.1
0020: BTFSS PORTB.4
0021: GOTO 020
0022: NOP
0023: BSF STATUS.5
0024: BCF TRISB.4
0025: BCF STATUS.5
0026: BCF PORTB.4
0027: GOTO 038 (RETURN)
....................
.................... void main() {
.................... char a;
0028: CLRF FSR
0029: MOVLW 1F
002A: ANDWF STATUS,F
002B: BSF STATUS.5
002C: BSF ADCON1.0
002D: BSF ADCON1.1
002E: BSF ADCON1.2
002F: BCF ADCON1.3
.................... osccon = 0x70; // Setea el oscilador a 8MHz
0030: MOVLW 70
0031: MOVWF
.................... while(!IOFS){} // Espera a que el reloj est� estable.
0032: BTFSS .2
0033: GOTO 032
.................... a= i2c_read();
0034: MOVLW 01
0035: MOVWF @77
0036: BCF STATUS.5
0037: GOTO @I2C_READ_0_52_49_8000000
0038: MOVF @78,W
0039: MOVWF a
....................
.................... }
....................
003A: SLEEP |
|
|
mpfj
Joined: 09 Sep 2003 Posts: 95 Location: UK
|
|
Posted: Wed Mar 16, 2005 1:42 pm |
|
|
cgperalta wrote: | Code: | .................... a= i2c_read();
0034: MOVLW 01
0035: MOVWF @77
0036: BCF STATUS.5
0037: GOTO @I2C_READ_0_52_49_8000000
0038: MOVF @78,W
0039: MOVWF a
|
|
You should check the function @I2C_READ_0_52_49_8000000 and see what that does. I think you will find that the code contained in that function uses the I2C hardware. |
|
|
cgperalta
Joined: 14 Mar 2005 Posts: 4
|
|
Posted: Wed Mar 16, 2005 2:20 pm |
|
|
the function @I2C_READ_0_52_49_8000000 goes to address 0x0004 and executes this:
0004: MOVLW 08
0005: MOVWF @@23
0006: BSF STATUS.5
0007: BSF TRISB.4
0008: BSF TRISB.1
0009: BCF STATUS.5
000A: BTFSS PORTB.4
000B: GOTO 00E
000C: BSF STATUS.5
000D: GOTO 009
000E: BTFSS PORTB.4
000F: GOTO 00E
0010: BTFSC PORTB.1
0011: BSF STATUS.0
0012: BTFSS PORTB.1
0013: BCF STATUS.0
0014: RLF @78,F
0015: DECFSZ @@23,F
0016: GOTO 018
0017: GOTO 01A
0018: BSF STATUS.5
0019: GOTO 009
001A: BTFSC PORTB.4
001B: GOTO 01A
001C: BSF STATUS.5
001D: BCF TRISB.1
001E: BCF STATUS.5
001F: BCF PORTB.1
0020: BTFSS PORTB.4
0021: GOTO 020
0022: NOP
0023: BSF STATUS.5
0024: BCF TRISB.4
0025: BCF STATUS.5
0026: BCF PORTB.4
0027: GOTO 038 (RETURN)
This is the listing for the same source code compiled with version 3.168:
.................... #use i2c(slave, fast, sda=PIN_B1, scl=PIN_B4, force_hw, address=0x01, restart_wdt)
....................
.................... void main() {
.................... char a;
0004: CLRF FSR
0005: MOVLW 1F
0006: ANDWF STATUS,F
0007: MOVLW 06
0008: BSF STATUS.5
0009: MOVWF ADCON1
000A: MOVLW 01
000B: MOVWF SSPADD
000C: MOVLW 36
000D: BCF STATUS.5
000E: MOVWF SSPCON
.....
.....
.................... a= i2c_read(0);
0015: BTFSS SSPSTAT.0
0016: GOTO 015
0017: BCF STATUS.5
0018: MOVF SSPBUF,W
0019: MOVWF a
This one uses the hardware SPI, the former doesn't.
The only change, is the compiler version!! |
|
|
Guest
|
Re: I2C Force_HW doesn't work... |
Posted: Wed Mar 16, 2005 9:01 pm |
|
|
cgperalta wrote: | I'm trying to compile a code using force_hw in #use i2c staement, but when I see the list, it's clearly seen that is using software routines to read the I2C Bus. I'm using 16F819 and PCM 3.216.
|
fixed in 3.222 |
|
|
cgperalta
Joined: 14 Mar 2005 Posts: 4
|
|
Posted: Fri Mar 18, 2005 9:50 am |
|
|
Thanks!
Have to buy new version now... |
|
|
gjmsd
Joined: 24 Mar 2005 Posts: 2
|
FORCE_HARDWARE |
Posted: Thu Mar 24, 2005 10:40 pm |
|
|
I have the same problem - I2C stops worling if is specify FORCE_HW. I have read the thread and am not finding my problem. Here's my code:
Code: | #use i2c(MASTER, SDA=PIN_C4, SCL=PIN_C3, FAST, FORCE_HW)
//#use i2c(MASTER, SDA=PIN_C4, SCL=PIN_C3, FAST)
#define EEPROM_SCL PIN_C3
#define EEPROM_SDA PIN_C4
void init_I2C(void)
{
output_float(EEPROM_SCL);
output_float(EEPROM_SDA);
}
int1 I2C_ready(void)
{
int1 bAck;
i2c_start();
bAck = i2c_write(0xa0);
i2c_stop();
return (!bAck);
}
void write_I2C_begin(long int address)
{
short int status;
while(!I2C_ready());
i2c_start();
i2c_write(0xa0);
i2c_write(address>>8);
i2c_write(address);
}
void write_I2C_data(BYTE data)
{
i2c_write(data);
}
void write_I2C_end(void)
{
i2c_stop();
}
void read_I2C_begin(long int address)
{
while(!I2C_ready());
i2c_start();
i2c_write(0xa0);
i2c_write(address>>8);
i2c_write(address);
i2c_start();
i2c_write(0xa1);
}
BYTE read_I2C_data(void)
{
BYTE data;
data=i2c_read();
return(data);
}
BYTE read_I2C_end(void)
{
BYTE data;
data=i2c_read(0);
i2c_stop();
return(data);
}
void Setup_Ports(void)
{
setup_adc_ports(NO_ANALOGS);
set_tris_a(0x10);
output_a(0x28);
set_tris_b(0x00);
port_b_pullups(TRUE);
set_tris_c(0x81);
output_c(0x38);
setup_timer_0(RTCC_EXT_L_TO_H | RTCC_DIV_1);
set_timer0(0);
setup_timer_1(T1_EXTERNAL);
set_timer1(0);
setup_timer_3(T3_INTERNAL | T3_DIV_BY_1);
set_timer3(0);
}
void main()
{
disable_interrupts(GLOBAL);
Setup_Ports();
output_low(PIN_C5);
disable_interrupts(INT_RB);
enable_interrupts(INT_TIMER0);
enable_interrupts(INT_TIMER1);
enable_interrupts(INT_TIMER3);
enable_interrupts(INT_SSP);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
init_I2C();
write_I2C_begin(0x00);
write_I2C_data(0xaa);
write_I2C_data(0xab);
write_I2C_data(0xac);
write_I2C_end();
read_I2C_begin(0x00);
write_eeprom(0x00, read_I2C_data());
write_eeprom(0x01, read_I2C_data());
write_eeprom(0x02, read_I2C_end());
}
|
|
|
|
gjmsd
Joined: 24 Mar 2005 Posts: 2
|
FORCE_HARDWARE |
Posted: Thu Mar 24, 2005 10:47 pm |
|
|
On my previous post I forgot to mention
PIC18F252
MPLAB 6.60
PCH 3.181 |
|
|
|
|
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
|