CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

A question about PIC18f25k40 OLED1306
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
bulut_01



Joined: 24 Feb 2024
Posts: 62

View user's profile Send private message

A question about PIC18f25k40 OLED1306
PostPosted: Sat Feb 24, 2024 2:01 pm     Reply with quote

Good day, I'm new to you. I'm having a hardware problem with i2c. My codes for i2c_transfer() are stuck. Can you help me with this?
I am using ccs 5.115 version, my pull up resistors are 3.3k circuit, working at 3volts
Note, this code works with software i2c oled lcd.

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)
//
#define SCL1 PIN_C3
#define SDA1 PIN_C4
#pin_select SCL1in = PIN_C3
#pin_select SDA1in = PIN_C4
//
#use i2c(master,I2C1, Fast, sda = PIN_C4, scl = PIN_C3 , STREAM = STREAM_24XX1025)
//#use i2c(master, sda=PIN_C4, scl=PIN_C3, FAST, stream = STREAM_24XX1025)
//
//#use rs232(baud = 2400, parity = N, xmit = PIN_C6, rcv = PIN_C7, bits = 8, STREAM = UART1, stop = 1, errors)
///////////////////////////////////////////////////////////////////////////////
/*
#BYTE SSPxCON1 = 0x0F95
#BIT SSPEN = SSPxCON1.5
#BIT WCOL = SSPxCON1.7
#BIT SSPM3 = SSPxCON1.3
#BIT SSPM2 = SSPxCON1.2
#BIT SSPM1 = SSPxCON1.1
#BIT SSPM0 = SSPxCON1.0
#BYTE SSPxCON2 = 0x0F96
#BIT GCEN = SSPxCON2.7
#BIT ACKSTAT = SSPxCON2.6
#BIT ACKDT = SSPxCON2.5
#BIT ACKEN = SSPxCON2.4
#BIT RCEN = SSPxCON2.3
#BIT PEN = SSPxCON2.2
#BIT RSEN = SSPxCON2.1
#BIT SEN = SSPxCON2.0
*/
//
#BYTE SSPxCON1 = 0x0F95
#BIT SSPEN = SSPxCON1.5
//
#BYTE SSPxCON2 = 0x0F96
#BIT SEN = SSPxCON2.0
#BIT RSEN = SSPxCON2.1
//
#byte anselc = 0xF21
/////////////////////////////////////////////////////////////////////////////////kütüphane ekleme
#include <ssd1306.C>                                     
#include <stdint.h>
///////////////////////////////////////////////////////////////////////////////
void main()                                                         
{
set_slow_slew_c(FALSE);
setup_spi(false);
i2c_init(true);
//SETUP_ADC(NO_ANALOGS || ADC_OFF);
set_analog_pins(NO_ANALOGS);
//
//setup_timer_0(T0_EXT_L_TO_H | T0_DIV_1);
//enable_interrupts(int_timer0);
//set_timer0(0);
//

Oled_Init();
oled_clearScreen();
oled_command(NORMALDISPLAY);
oled_line( 6, 8, 32, 127, 6);

//Oled_FillScreen(); //ekranı temizler
//
//setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
//enable_interrupts(INT_TIMER1);
//set_timer1(0);
//
//setup_timer_2(T2_DIV_BY_64,255,1);                                   //3.2 ms
//enable_interrupts(INT_TIMER2);
//set_timer2(0);
//

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);
set_open_drain_c(0B0011000);
//
SSPEN = 1;
anselc = 0;
//
//set_slow_slew_a(false);
//set_slow_slew_b(false);
//set_slow_slew_c(false);
//



                            while(true){     

                 
}}
bulut_01



Joined: 24 Feb 2024
Posts: 62

View user's profile Send private message

PostPosted: Sun Feb 25, 2024 6:36 am     Reply with quote

Is there anyone who can help with this?
temtronic



Joined: 01 Jul 2010
Posts: 9120
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Feb 25, 2024 6:47 am     Reply with quote

1st thing to do, run the I2C Scanner program in the code library here and confirm the I2C device IS at the correct address.

2nd, since this PIC has PPS, confirm you can attach MSSP( I2C) to the pins you've chosen. Not all internal peripherals can be connected to all pins.

I suspect #2 is the problem as you say software I2C runs. Software I2C is bigbanging,doesn't use the internal hardware,so will always work with any two pins.

Also be sure to have an ISR for the I2C if you've enabled it's interrupt. I don't have ssd1306.c which I assume is the OLED driver. it is quite possible something in there is causing the problem.

and, LCD's are slow powerup devices, so I always have a delay_ms(500) before 'initializing' them.
bulut_01



Joined: 24 Feb 2024
Posts: 62

View user's profile Send private message

PostPosted: Sun Feb 25, 2024 7:27 am     Reply with quote

Can you show your 1st and 2nd explanations in code? I couldn't understand you very well.
temtronic



Joined: 01 Jul 2010
Posts: 9120
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Feb 25, 2024 8:06 am     Reply with quote

#1...
http://www.ccsinfo.com/forum/viewtopic.php?t=49713
should be the link to PCPM's I2C scanner program

copy it, compile, install, run......

#2...
While I don't use any PICs with PPS, not all internal peripherals can be used with every I/O pin, so you have to read the datasheet to see what is allowed.
In the datasheet it does say that both input and output functions of a bidirectional device must be programmed,so you need TWO PPS selects for i2C data.

others that use these newer PICs may reply and correct me if I'm wrong.
bulut_01



Joined: 24 Feb 2024
Posts: 62

View user's profile Send private message

PostPosted: Sun Feb 25, 2024 8:33 am     Reply with quote

I did what you said, I've been trying for 2 days and I couldn't get it to work. When I debug, the code gets stuck in the i2c_transfer() function and it doesn't work.
Ttelmah



Joined: 11 Mar 2010
Posts: 19238

View user's profile Send private message

PostPosted: Sun Feb 25, 2024 9:24 am     Reply with quote

i2c_transfer?????.

None of the code you are using should be using i2c_transfer. The I2C
scanner program does not use this, and the ssd1306 driver does not
use this.
Use the I2C scanner as it is posted. Just with your chip header, and
the i2C setup. The setup should be:
Code:

#pin_select SCL1in = PIN_C3
#pin_select SDA1in = PIN_C4

#use i2c(master,I2C1, Fast)


Then if you are using my ssd1306 driver, you are not initialising the chip.
Look at the example code posted. You have to send the initialisation
sequence to actually program the controller. If you are not using my
driver, then you need to tell us what driver you are using.
bulut_01



Joined: 24 Feb 2024
Posts: 62

View user's profile Send private message

PostPosted: Sun Feb 25, 2024 9:39 am     Reply with quote

The codes I have tried are below. I am using the SSD1306 standard ccs library. It gets stuck in the i2c_transfer() function. I am simulating Proteus and debugging, my code does not work. I2c does not work in hardware, the same code works in software.

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,STREAM = STREAM_24XX1025)
//#use i2c(master,I2C1, FAST, sda = SDA_PIN, scl = SCL_PIN, STREAM = STREAM_24XX1025) //HARDWARE
//#use i2c(master, sda=OLED_SDA, scl=OLED_SCL, 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 SSPxCON1 = 0x0F95
#BIT SSPEN = SSPxCON1.5
#BIT WCOL = SSPxCON1.7
#BIT SSPM3 = SSPxCON1.3
#BIT SSPM2 = SSPxCON1.2
#BIT SSPM1 = SSPxCON1.1
#BIT SSPM0 = SSPxCON1.0
//
#BYTE SSPxCON2 = 0x0F96
#BIT GCEN = SSPxCON2.7
#BIT ACKSTAT = SSPxCON2.6
#BIT ACKDT = SSPxCON2.5
#BIT ACKEN = SSPxCON2.4
#BIT RCEN = SSPxCON2.3
#BIT PEN = SSPxCON2.2
#BIT RSEN = SSPxCON2.1
#BIT SEN = SSPxCON2.0
*/
//
/*
#BYTE SSPxCON1 = 0x0F95
#BIT SSPEN = SSPxCON1.5
#BIT WCOL = SSPxCON1.7
#BIT SSPOV = SSPxCON1.6
#BIT CKP = SSPxCON1.4
#BIT SSPM3 = SSPxCON1.3
#BIT SSPM2 = SSPxCON1.2
#BIT SSPM1 = SSPxCON1.1
#BIT SSPM0 = SSPxCON1.0
//
#BYTE SSPxCON2 = 0x0F96
#BIT SEN = SSPxCON2.0
#BIT RSEN = SSPxCON2.1
#BIT ACKEN = SSPxCON2.4
#BIT RCEN = SSPxCON2.3
//
#BYTE SSPxCON3 = 0x0F98
#BIT ACKTIM = SSPxCON3.7
#BIT PCIE = SSPxCON3.6
#BIT SCIE = SSPxCON3.5
#BIT BOEN = SSPxCON3.4
//
#BYTE SSPxSTAT = 0x0F95
#BIT SMP = SSPxSTAT.7
#BIT CKE = SSPxSTAT.6
#BIT DA = SSPxSTAT.5
*/
//
#byte anselc = 0xF21
#BYTE SSPxCON1 = 0x0F95
#BIT SSPEN = SSPxCON1.5
/////////////////////////////////////////////////////////////////////////////////kütüphane ekleme
#include <ssd1306.C>

///////////////////////////////////////////////////////////////////////////////
void main()                                                         
{
//SSPEN = 1;
//
setup_spi(false);
set_analog_pins(NO_ANALOGS);
//SETUP_ADC(NO_ANALOGS || ADC_OFF);
//
//setup_timer_0(T0_EXT_L_TO_H | T0_DIV_1);
//enable_interrupts(int_timer0);
//set_timer0(0);
//
i2c_init(true);
i2c_start();
delay_ms(500);
Oled_Init();
oled_clearScreen();
oled_command(NORMALDISPLAY);
oled_line( 5, 10, 50, 30, 6);

//Oled_FillScreen(); //ekranı temizler
//
//setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
//enable_interrupts(INT_TIMER1);
//set_timer1(0);
//
//setup_timer_2(T2_DIV_BY_64,255,1);                                   //3.2 ms
//enable_interrupts(INT_TIMER2);
//set_timer2(0);
//

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);
//set_open_drain_c(0B0011000);
anselc = 0;
//
/*
ACKEN = 1;
RCEN = 1;
RSEN = 1;
SEN = 1;
//
ACKTIM = 1;
PCIE = 1;
SCIE = 1;
BOEN = 1;
//
CKE = 1;
DA = 1;
//
WCOL = 1;
SSPOV = 0;
CKP = 1;
SSPM3 = 1;
SSPM2 = 0;
SSPM1 = 0;
SSPM0 = 0;
*/
//
//set_slow_slew_a(false);
//set_slow_slew_b(false);
//set_slow_slew_c(false);
//



                       while(true){     
               
}}
bulut_01



Joined: 24 Feb 2024
Posts: 62

View user's profile Send private message

PostPosted: Sun Feb 25, 2024 9:45 am     Reply with quote

The code is stuck at this part and does not work

[/img]
Ttelmah



Joined: 11 Mar 2010
Posts: 19238

View user's profile Send private message

PostPosted: Sun Feb 25, 2024 9:59 am     Reply with quote

The point is you are trying to run before you can walk.

Start with the I2C scanner program from the code library. It is _VITAL_
to know what the I2C address of the chip is, and that the hardware is
working before you try to run something as complex as this driver.
I'd suspect that you will find that your display is actually wired for the
secondary addresses, hence why the driver does not work.
You need to find this sort of thing out before trying to use the driver.
bulut_01



Joined: 24 Feb 2024
Posts: 62

View user's profile Send private message

PostPosted: Sun Feb 25, 2024 10:18 am     Reply with quote

I understand what you mean. Only the processor i2c setup is stuck. In short, nothing is working. The scanner you say does not work because the i2c setup is stuck and no code works because the processor is locked.

The code hangs here. It seems like there is a hardware problem with ccs c i2c.
Code:
#use i2c(master,I2C1, FAST, sda = PIN_C4, scl = PIN_C3, STREAM = STREAM_24XX1025)
Ttelmah



Joined: 11 Mar 2010
Posts: 19238

View user's profile Send private message

PostPosted: Sun Feb 25, 2024 10:29 am     Reply with quote

I posted how to setup the #USE I2C for the scanner. You don't want
the pin numbers (these are set by the PIN_SELECT statements), and
the stream name. Try with slow first.
bulut_01



Joined: 24 Feb 2024
Posts: 62

View user's profile Send private message

PostPosted: Sun Feb 25, 2024 10:31 am     Reply with quote

I posted the code above. What is the missing or wrong part? The same thing you said is in the code.
Ttelmah



Joined: 11 Mar 2010
Posts: 19238

View user's profile Send private message

PostPosted: Sun Feb 25, 2024 10:49 am     Reply with quote

No. You are missing the point. You need to start by using the I2C scanner
program from the code library, do not try to drive the OLED.
Just us the basic I2C setup of:
Code:
[
#pin_select SCL1in = PIN_C3
#pin_select SDA1in = PIN_C4

#use i2c(master,I2C1, slow)


With the existing code, the I2C setup should change to:

#use i2c(master,I2C1, FAST=400000, STREAM = STREAM_24XX1025)

You do need the
Code:

set_slow_slew_a(false);
set_slow_slew_b(false);
set_slow_slew_c(false);


and to set all the pins as non analog, before _any_ I2C transaction is attempted.
Also get rid of your setup_spi line. This is potentially turning the I2C
peripheral off. The SPI and I2C are handled by the same peripheral.
bulut_01



Joined: 24 Feb 2024
Posts: 62

View user's profile Send private message

PostPosted: Sun Feb 25, 2024 11:22 am     Reply with quote

My friend, thank you for your attention. I did what you said, the code always crashes in the same place, in short, I could not run SSD1306 with i2c hardware. Do you know of an example that runs 1306 with i2c hardware?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
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