View previous topic :: View next topic |
Author |
Message |
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Sun Feb 25, 2024 11:28 am |
|
|
Please compile and run the I2C scanner program. report back what it says.
You NEED to do this for us to help you. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Sun Feb 25, 2024 11:28 am |
|
|
There is no point in asking about driving the OLED, till you get the I2C
scanner working.
Are you saying that if you use the I2C scanner program this too crashes
the same way?. If so something radical is wrong with your board or chip. |
|
|
bulut_01
Joined: 24 Feb 2024 Posts: 62
|
|
Posted: Sun Feb 25, 2024 12:25 pm |
|
|
i2cScanner.c
Code: | int8 i = 0;
int8 count = 0;
void i2cScanner(){
int8 count = 0;
printf("\n\rStart I2C Scanner..\n\r");
for(int8 i=0x10; i < 0xF0; i+=2) {
i2c_start();
if(i2c_write(i) == 0) { printf("ACK addr: 0x%X\n\r", i); count++; }
i2c_stop();
}
if(count == 0) {printf("Nothing Found\n\r"); }
else { printf("Number of i2c chips found: %u\n\r", count); }
}
|
main.c
Code: |
#include <18f25k40.h>
#device ADC = 8
//#FUSES PROTECT // kod koruması
//#FUSES CPD
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOPUT //No Power Up Timer
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOMCLR //Master Clear pin disabled
#FUSES NOPUT
#FUSES NOLVP
#FUSES NOSTVREN
#FUSES NOFCMEN
#FUSES NOWRT
#FUSES NODEBUG
#fuses NOEBTRB
#fuses NOEBTR
#use delay(internal = 64M)
//
#OPT 9
//
//#use fast_io(ALL)
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
//
#pin_select SCL1in = PIN_C3
#pin_select SDA1in = PIN_C4
//
#use i2c(master,I2C1,fast)
//#use i2c(master,I2C1, FAST, sda = PIN_C4, scl = PIN_C3, STREAM = STREAM_24XX1025) //HARDWARE
//#use i2c(master, sda = PIN_C4, scl = PIN_C3, FAST, stream = STREAM_24XX1025) //SOFTWARE
//
#use rs232(baud = 2400, parity = N, xmit = PIN_C6, rcv = PIN_C7, bits = 8, STREAM = UART1, stop = 1, errors)
///////////////////////////////////////////////////////////////////////////////
#byte anselc = 0xF21
#BYTE SSPxCON1 = 0x0F95
#BIT SSPEN = SSPxCON1.5
/////////////////////////////////////////////////////////////////////////////////kütüphane ekleme
//#include <ssd1306.C>
#include <i2cScanner.c>
///////////////////////////////////////////////////////////////////////////////
void main()
{
i2cScanner();
set_analog_pins(NO_ANALOGS);
//SETUP_ADC(NO_ANALOGS || ADC_OFF);
//
/*
i2c_init(true);
delay_ms(500);
Oled_Init();
oled_clearScreen();
oled_command(NORMALDISPLAY);
oled_line( 5, 10, 50, 30, 6);
*/
disable_interrupts(int_rda);
disable_interrupts(INT_TBE);
enable_interrupts(GLOBAL);
//
output_A(0x00);
output_B(0x00);
output_C(0x00);
//
set_tris_A(0b0000000);
set_tris_B(0b0000000);
set_tris_C(0b0011000);
//
anselc = 0;
set_slow_slew_a(false);
set_slow_slew_b(false);
set_slow_slew_c(false);
while(true){
}}
|
code i2c_start(); hanging out here
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Sun Feb 25, 2024 12:52 pm |
|
|
well of course it doesn't work !!
You're using PROTEUS !!!! Which everyone KNOWS is DEFECTIVE,aka does NOT work !!!
there's a 'sticky' up above, please read it....
Now ,when you get REAL hardware, run I2C Scanner and report what it says |
|
|
bulut_01
Joined: 24 Feb 2024 Posts: 62
|
|
Posted: Sun Feb 25, 2024 12:59 pm |
|
|
I will write here what happened when I built the real circuit. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Sun Feb 25, 2024 3:40 pm |
|
|
BTW the Proteus schematic that you posted can't possibly work in the real world...... |
|
|
bulut_01
Joined: 24 Feb 2024 Posts: 62
|
|
Posted: Sun Feb 25, 2024 5:06 pm |
|
|
why ? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Sun Feb 25, 2024 6:52 pm |
|
|
Why ?
Simple, as shown...
1) No VDD to PIC
2) No VSS to PIC
3) _MCLR not connected
4) No bypass caps on VDD and VSS
5) no xtal/2 caps
6) I2CCLK pullup not connected to PIC VDD
7) I2CDTA pullup not connected to PIC VDD
So if you were given the schematic and all the parts, wired it as shown on a white breadboard, wirewrapped, homemade PCB,solder stiched , it can never work. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Mon Feb 26, 2024 12:34 am |
|
|
Half of those Proteus does do for him. The supply connections are made.
However the lack of pullup on MCLR and the decoupling would both stop
it working.
He is also ignoring what I said about needing the slew rate control and
analog setup _before_ doing anything to the I2C. |
|
|
bulut_01
Joined: 24 Feb 2024 Posts: 62
|
|
Posted: Mon Feb 26, 2024 2:05 am |
|
|
Maybe you're right, it will actually become clear when you set it up. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Mon Feb 26, 2024 3:50 am |
|
|
OK. Since you are trying in Proteus (understand this is a _waste of time_
- projects that on the real chip work perfectly, won't work often in this, and
projects this says works, often won't work on the real chip), I sat back,
wrote the scanner program as needed, and ran this up in Proteus.
Works fine:.....
Code: |
#include <18f25k40.h>
#device ADC = 8
#FUSES NOWDT //No Watch Dog Timer
#FUSES PUT //Power Up Timer
#FUSES BROWNOUT //Brownout reset
#FUSES BORV28 //2.8v brownout
#FUSES NOMCLR //Master Clear pin disabled
#FUSES NOLVP
#FUSES STVREN
#FUSES FCMEN
#FUSES NOWRT
#use delay(internal = 64MHz)
//Setup I2C
#pin_select SCL1 = PIN_C3
#pin_select SDA1 = PIN_C4
#use i2c(master,I2C1,fast=400000, STREAM=I2C1) //Important to specify speed
//Setup UART
#pin_select RX1 = PIN_C7
#pin_select TX1 = PIN_C6
#use rs232(baud = 2400, parity = N, bits = 8, stop = 1, errors, STREAM = UART1)
void i2cScanner(void)
{
int8 count = 0;
int8 i;
fprintf(UART1,"\n\rStart I2C Scanner..\n\r");
for(i=0x10; i < 0xF0; i+=2)
{
i2c_start(I2C1);
if(i2c_write(I2C1,i) == 0)
{
fprintf(UART1,"ACK addr: 0x%X\n\r", i);
count++;
}
i2c_stop(I2C1);
}
if(count == 0)
fprintf(UART1,"Nothing Found\n\r");
else
fprintf(UART1,"Number of i2c chips found: %u\n\r", count);
}
void main()
{
//configure pins first
set_analog_pins(NO_ANALOGS);
set_slow_slew_a(false);
set_slow_slew_b(false);
set_slow_slew_c(false);
//scan _after_ the setup
i2cScanner();
while(true)
{
delay_cycles(1); //NOP
}
}
|
|
|
|
bulut_01
Joined: 24 Feb 2024 Posts: 62
|
|
Posted: Mon Feb 26, 2024 9:12 am |
|
|
This code doesn't work for me. i2c_start(I2C1); It gets stuck at this part.
note. I'm trying Proteus in simulation |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Mon Feb 26, 2024 10:27 am |
|
|
Are you sure you have the I2C peripheral setup correctly in Proteus?.
Ask on a Proteus forum about how to do this. Mine has a load of setups
I configured a while ago, and it does work correctly. It sounds to me as
if yours does not have this setup right. Remember you have to configure
the pins the peripheral uses in Proteus. It does not implicitly understand
the PPS settings. |
|
|
bulut_01
Joined: 24 Feb 2024 Posts: 62
|
|
Posted: Mon Feb 26, 2024 10:57 am |
|
|
How do you make these Proteus configuration settings? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Mon Feb 26, 2024 11:14 am |
|
|
As Mr. T. points out, ask on a PROTEUS forum.
This CCS forum is about using their compiler, not the Proteus software.
You really need to ask Proteus as to how to configure,setup,run their software.
Just remember,even though your code 'works' in a Proteus simulation ,that does NOT mean it WILL work in a real PIC !!! |
|
|
|