paulfjujo
Advanced Member level 4
- Joined
- Jun 9, 2008
- Messages
- 1,464
- Helped
- 298
- Reputation
- 596
- Reaction score
- 283
- Trophy points
- 1,363
- Location
- France 01800
- Activity points
- 10,545
hello,
i turn around this probleme since any days
did many tests without succes ..
Impossible to get the ACK from slave device with A PIC16F1619 as Master I2C.
I am using I2C remappable from MikroC
This PIC uses PPS to map IN/OUT and fonctions
I tested the I2C Bus with a SSD1306 LCD, a RTC DS3231 and an LCD+PCF8754 .. same problem
On teh data sheet of this PIC, I2C is a bit different than classical I2C
Extra Registers and flags have been added ..
I tried also some code from Github OLED LCD .. without succes
No executable code *.Hex (correponding to the project ) is delivered, so i can't trust also with this code .
If someone successfully tested this PIC with I2C hardware, please post a copy of your *.hex and config.
here is my code
i am using a IKALOGIC analyser on I2C bus
my results, connected to a RTC DS3231
No ACK follow the adresse
hardware
R pullup on I2C bus = 4.7K
i turn around this probleme since any days
did many tests without succes ..
Impossible to get the ACK from slave device with A PIC16F1619 as Master I2C.
I am using I2C remappable from MikroC
This PIC uses PPS to map IN/OUT and fonctions
I tested the I2C Bus with a SSD1306 LCD, a RTC DS3231 and an LCD+PCF8754 .. same problem
On teh data sheet of this PIC, I2C is a bit different than classical I2C
Extra Registers and flags have been added ..
I tried also some code from Github OLED LCD .. without succes
No executable code *.Hex (correponding to the project ) is delivered, so i can't trust also with this code .
If someone successfully tested this PIC with I2C hardware, please post a copy of your *.hex and config.
here is my code
Code:
#define VERSION "2020_01_22"
//ac:Shema_16F1619
// ac:Pinout_16F1619
// cocher High voltage ICSP Options MPLAB IPE et Pickit4
//
// Hardware 16F1619 DIP20 :
/*
PIN 1 VDD +5V
PIN 2 RA5
PIN 3 RA4 output --> Led Rouge ---2.2K--+5V
|---750--ICSP VPP PIN 1 Pickit2
Pin 4 RA3/ MCLR |--- 6,8K --- +5V
Pin 5 RC5 ---> sortie SQA synchro ( Led Bleue )
pin 6 RC4
pin 7 RC3
pin 8 RC6
pin 9 RC7
pin 10 RB7 TX ----> UART ---> Ecran fil Blanc Prolific USB
-----
Pin 20 VSS --+5V
Pin 19 RA0 --- ICSP Data
Pin 18 RA1 --- ICSP Clock
Pin 17 RA2
Pin 16 RC0 --- SPI Clck
Pin 15 RC1
pin 14 RC2
pin 13 RB4 <---> SDA I2C
pin 12 RB5 Rx <--- UART <--- clavier fil vert Prolific USB
pin 11 RB6 <--> SCL I2C
*/
#define PROJECT "Test_16F1619_I2C1_Hw_2020.mcppi"
#define SOURCE "_16F1619_Test_I2C"
#define Langage "MikroC 7.6.0"
#define PROCESSOR "PIC 16F1619 "
#define DEVICES "OLED DISPLAY IIC I2C 0.91 128x32"
#define EEPROM "No....ihex"
#define POWER_SUPPLY "DC_5V"
#define OSCILLATEUR_INTERNE
#define FOSC "16.0" // MHz
#define BAUD "19200" // UART1
#define OTHERS " "
/* config bits
CONFIG1 : $8007 : 0x38E4
CONFIG2 : $8008 : 0x1E83
CONFIG3 : $8009 : 0x3F1F
*/
//
#include "built_in.h" // for Hi Lo ..etc
#define CLS 12
#define CR 13
#define LF 10
#define TAB 9
#define BACK 8
#define Beep 7
#define Separator 0x20 // space
#define Byte unsigned char
#define ON 0
#define OFF 1
//#define LCD_ADDR 0x4E //
#define Word unsigned int
//#define OLED_ADDRESS 0x78 //@ I2C sur 8 bits
//#define OLED_ADDRESS 0x3C //@ I2C sur 7 bits
sbit Led_Rouge at LATA.B4;
sbit Led_Rouge_Dir at TRISA.B4;
sbit SQA at LATC.B5;
sbit SQA_Dir at TRISC.B5; // avec Led_Bleue
unsigned int OLED_ADRESS=0x0078;
unsigned int addr;
int i,j,k,l,m,n;
void Init_Hardware(void) ;
void strConstRamCpy(unsigned char *dest, const code char *source);
void Init_Hardware()
{
//REGISTER 6-1: BORCON: BROWN-OUT RESET CONTROL REGISTER
BORCON.SBOREN=0;
// no analog on PORT A,B,C
ANSELA=0;
TRISA=0xFF;
Led_Rouge_Dir=0; // RA4
Led_Rouge=0;
ANSELB=0;
TRISB=0b11111111;
// I2C pin must be set as input and Open drain
WPUB=0 ;// Weak pull up on port B RB4-RB7 : 0=DISABLED
// 1=open drain 0=push pull output
ODCONB.B4 = 1; // 1=open drain output SDA
ODCONB.B6 = 1; // 1=open drain output SCL
ODCONB.B5 = 0; // 0=push pull input RX
ODCONB.B7 = 0; // 0=push pull output TX
SLRCONB=0xF0; // 1 = Port pin slew rate is limited
INLVLB=0x00; //1 = ST input used for PORT reads and interrupt-on-change
ANSELC=0;
TRISC=0b11011111; // RC5 output SDA et Led Bleue
WPUC=0b00100000 ;// Weak pull up on port C RC5
ODCONC.B5 = 1; //
SQA_Dir=0; //RC5 SQA led Bleue tirée au +Vcc
SQA=0;
// page 230
OPTION_REG.nWPUEN =0; // 0= Weak pull-ups are enabled by individual WPUx latch values 1=disable WPUP
}
void Init_Fosc(void)
{
// internal FOSC
/*
bit 7 SPLLEN: Software PLL Enable bit
bit 6-3 IRCF<3:0>: Internal Oscillator Frequency Select bits
1111 =16 MHz HF
1110 =8 MHz HF
1101 =4 MHz HF
1100 =2 MHz HF
1011 =1 MHz HF
1010 =500 kHz HF(1)
1001 =250 kHz HF(1)
1000 =125 kHz HF(1)
0111 =500 kHz MF (default upon Reset)
0110 =250 kHz MF
0101 =125 kHz MF
0100 =62.5 kHz MF
0011 =31.25 kHz HF(1)
0010 =31.25 kHz MF
000x =31 kHz LF
bit 2
bit 1-0 SCS<1:0>: System Clock Select bits
*/
OSCCON=0;
// 16 MHZ
OSCCON.IRCF3=1;
OSCCON.IRCF2=1;
OSCCON.IRCF1=1;
OSCCON.IRCF0=1;
// 1x = Internal oscillator block
OSCCON.SCS1=1;
OSCTUNE=0;
}
void I2C1_TimeoutCallback(char errorCode) {
if (errorCode == _I2C_TIMEOUT_RD) {
// do something if timeout is caused during read
}
if (errorCode == _I2C_TIMEOUT_WR) {
// do something if timeout is caused during write
}
if (errorCode == _I2C_TIMEOUT_START) {
// do something if timeout is caused during start
}
if (errorCode == _I2C_TIMEOUT_REPEATED_START) {
// do something if timeout is caused during repeated start
}
}
void Config_PPS(void)
{
Unlock_IOLOCK();
RC5PPS=0;
RA4PPS=0;
// ---------- Peripheral PIN and EUSART configuration ----------------------
RB5PPS = 0x0D; // RX RB5
RB7PPS= 0x12; // TX RB7
// --- I2C ----------------------
// TABLE 13-2: AVAILABLE PORTS FOR OUTPUT BY PERIPHERAL
// REGISTER 13-2: RxyPPS: PIN Rxy OUTPUT SOURCE SELECTION REGISTER
// bit 7-5=0 bit 4-0 RxyPPS<4:0>: Pin Rxy Output Source Selection bits
RB6PPS = 0x10; // 0b00010000; // 16 RB6->MSSP:SCL
RB4PPS = 0x11; //0b00010001; // 17 RB4->MSSP:SDA;
// TABLE 13-1: PPS INPUT REGISTER RESET VALUES
// SPI and I2C clock SSPCLKPPS RB6
SSPCLKPPS = 0x0E; //RB6->MSSP:SCL;
// SPI and I2C data SSPDATPPS RB4
SSPDATPPS = 0x0C; //RB4->MSSP:SDA;
RC5PPS=0;
RA4PPS=0;
Lock_IOLOCK();
}
void main()
{
Init_Fosc(); // internal FOSC 1111 =16 MHz HF
Init_Hardware() ;
Config_PPS();
//6 x Clignotement Led Rouge (RA4) et SQA (RC5)\r\n");
// run once this , to check if MCU is running
/*
for (i=0;i<6;i++)
{
Led_Rouge=ON;
Delay_1sec(); // de visu
Led_Rouge=OFF;
Delay_1sec(); // de visu
}
I2C1_Remappable_Init(400000);
I2C1_SetTimeoutCallback(10, I2C1_TimeoutCallback);// Delai entre AC/Nack et bit de STOP
I2C_Set_Active(&I2C1_Remappable_Start, &I2C1_Remappable_Repeated_Start, &I2C1_Remappable_Rd, &I2C1_Remappable_Wr, &I2C1_Remappable_Stop, &I2C1_Remappable_Is_Idle);
do
{
SQA=1; // synchro IKALOGIC SQA50 ANalyser
I2C1_Remappable_Start();
//I2C1_Remappable_Wr(0x78);// OLED SSD1306 adresse 7 bits ou 0x78 adresse/8bits
I2C1_Remappable_Wr(0xD0);// 0xD0 RTC adresse/8bits
I2C1_Remappable_Wr(0x11);
I2C1_Remappable_Stop();
SQA=0;
Delay_ms(1000);
}
while(1);
}
i am using a IKALOGIC analyser on I2C bus
my results, connected to a RTC DS3231
No ACK follow the adresse
hardware
R pullup on I2C bus = 4.7K