It is currently 15 Dec 2018 08:43

All times are UTC + 1 hour




Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: 17 Jul 2015 13:39 
Offline

Joined: 25 Sep 2012 23:51
Posts: 125
Location: Sweden
I have moved a library for OLED (SDD1303) from the MPLAB X to mikroC PRO for PIC18F4550 and it works OK.

But now I wanted to use a PIC18F46K22 instead and I could not have it to work. What I am doing wrong?

I have connect SDA1 to RC4 and SCL1 To RC3 on PIC18F46K22.

The testprogram is this:
#include "font.h"
#include "SSD1306.h"


#define led_On       LATD5_bit = 1 ;
#define led_Off      LATD5_bit = 0 ;



void main() {
     ADCON1 = 0b00001111 ;          // Configure AN pins as digital I/O
     TRISA  = 0b00100000 ;
     TRISB  = 0b00000000 ;
     TRISC  = 0b00000000 ;
     TRISD  = 0b00000000 ;
     TRISE  = 0b00000000 ;
     LATE   = 0b00000000 ;
     LATB   = 0b00000000 ;
     LATC   = 0b00000000 ;
     LATD   = 0b00000000 ;
     ANSELC = 0b00000000 ;

     OSCCON = 0b01100000 ;
     I2C1_Init(100000);
     Oled_Init();
     Oled_FillScreen(0x00);
     Oled_SetFont(Terminal12x16, 12, 16, 32,127);
     Oled_FillScreen(0x00);// Clear display
     Oled_ConstText("*TROTTLE*  ", 0,0) ;

     
do {

      led_On;
      delay_ms(500) ;
      led_Off;
      delay_ms(500) ;

      }while(1);
}

The led is for to se where the program stop. And it is on the first attempt to write a command to the OLED. In the file SSD1303.H
Here, you can see where it hangs.(at the end of this programtext)
#ifndef SSD1306_H
#define        SSD1306_H

//12C_ADDRESS    0x78

 //Declaration of global variables.
//------------------------------------------------------------------------------
typedef char                     schar;
typedef unsigned char            uchar;
typedef const char               cschar;
typedef const unsigned char      cuchar;
typedef int                      sint;
typedef unsigned int             uint;

cuchar *font, *font2;
uchar width, height, minimum, maximum;

// Function Prototypes.
//------------------------------------------------------------------------------
void Oled_Init(void);
void Oled_Command(uchar cmd);
void Oled_WriteRam(uchar dat);
void Oled_SetPointer(uchar seg, uchar pag);
void Oled_SetFont(cuchar *_font, uchar _width, uchar _height, uchar _min, uchar _max);
void Oled_WriteChar(uchar c, uchar seg, uchar pag);
void Oled_ConstText(cschar *buffer, uchar seg, uchar pag);
void Oled_Text(schar *buffer, uchar seg, uchar pag);
void Oled_FillScreen(uchar pattern);
void Oled_Image(cuchar *buffer);
void Right_HorizontalScroll(uchar start_page, uchar end_page, uchar set_time);
void Left_HorizontalScroll(uchar start_page, uchar end_page, uchar set_time);
void VerticalRight_HorizontalScroll(uchar start_page, uchar end_page, uchar set_time);
void VerticalLeft_HorizontalScroll(uchar start_page, uchar end_page, uchar set_time);
void Deactivate_Scroll(void);
void Activate_Scroll(void);
//------------------------------------------------------------------------------

// Initializes the OLED module.
//------------------------------------------------------------------------------
void Oled_Init(void){
Delay_ms(500);

Oled_Command(0xAE);                     // Set Display OFF
Oled_Command(0x81); Oled_Command(0xCF); // Set Contrast Control
Oled_Command(0xA4);                     // Entire Display ON
Oled_Command(0xA6);                     // Set Normal

Oled_Command(0x20); Oled_Command(0x02); // Set Memory Addressing Mode
Oled_Command(0x00);                     // Set Lower Column
Oled_Command(0x10);                     // Set Higher Column
Oled_Command(0xB0);                     // Set Page Start

Oled_Command(0x40);                     // Set Display Start Line
Oled_Command(0xA1);                     // Set Segment Re-map
Oled_Command(0xA8); Oled_Command(0x3F); // Set Multiplex Ratio
Oled_Command(0xC8);                     // Set COM Output
Oled_Command(0xD3); Oled_Command(0x00); // Set Display Offset
Oled_Command(0xDA); Oled_Command(0x12); // Set COM Pins Hardware Configuration

Oled_Command(0xD5); Oled_Command(0x80); // Set Display Clock
Oled_Command(0xD9); Oled_Command(0xF1); // Set Pre-charge Period
Oled_Command(0xDB); Oled_Command(0x40); // Set VCOMH Deselect Level
Oled_Command(0x8D); Oled_Command(0x14); // Charge Pump Setting

Oled_Command(0xAF);                     // Set Display ON
Oled_FillScreen(0x00);                  // Clear screen
}

// Write command.
//------------------------------------------------------------------------------
void Oled_Command(uchar cmd){
I2C1_Start();
I2C1_Wr(0x78);  // ******************This command causes the program to stop ******************
I2C1_Wr(0x00);  // Co = 0, D/C = 0
I2C1_Wr(cmd);
I2C1_Stop();
}
//------------------------------------------------------------------------------
// The headerfile continues but I omit the rest of the program

I use the internal clock PIC18F4550 = 8 MHz and OSCCON = 0b01110000 ;
In PIC18F4622 I set internal clock = 16 MHz and OSCCON = 0b01100000 ;
I have tryed to use SDA2, SCL2 on pin RD1 and RD0 But no success.

_________________
Regards

Plain common sense is not very common.


Last edited by Seniorlemuren on 21 Jul 2015 10:02, edited 1 time in total.

Top
 Profile  
 
PostPosted: 17 Jul 2015 18:00 
Offline

Joined: 24 Jun 2007 19:27
Posts: 1067
Location: 01800 St Maurice de Gourdans France
hello,

the internal oscillator need a little time to be stable
try this

//OSCCON = 0b01110010  ; //0x72 ;     //Oscillateur à 16Mhz
OSCCON = 0b01100010  ; //0x62 ;     //Oscillateur à 8Mhz
OSCTUNE.PLLEN=0;
while (OSCCON.HFIOFS==0); // wait stable oscillator



and

  TRISC.TRISC3 = 1;  // SCL I2C
  TRISC.TRISC4 = 1;  // SDA I2C


I2Cinit will do the correct I/O assignment..


Top
 Profile  
 
PostPosted: 17 Jul 2015 23:21 
Offline

Joined: 25 Sep 2012 23:51
Posts: 125
Location: Sweden
Thank you, but still the same problem. It hang on the first attempt to Write: I2C2_Wr(0x78); (The led is not blinking.)

_________________
Regards

Plain common sense is not very common.


Top
 Profile  
 
PostPosted: 18 Jul 2015 15:16 
Offline

Joined: 24 Jun 2007 19:27
Posts: 1067
Location: 01800 St Maurice de Gourdans France
I2C2_Wr(0x78);


init with I2C1 .. ?


Top
 Profile  
 
PostPosted: 18 Jul 2015 16:55 
Offline

Joined: 25 Sep 2012 23:51
Posts: 125
Location: Sweden
No. I have changed that value several times from time to time when I was testing the other I2C-port. The copy of main file and the header file its between 2 different test. Of cource I have I2C1 in the header when I init with I2C1 and I2C2 in the header when I init with I2C2. Sorry I misguided. :)

_________________
Regards

Plain common sense is not very common.


Top
 Profile  
 
PostPosted: 18 Jul 2015 18:30 
Offline

Joined: 24 Jun 2007 19:27
Posts: 1067
Location: 01800 St Maurice de Gourdans France
hello,

Quote:
I have moved a library for OLED (SDD1303) from the MPLAB X to mikroC PRO for PIC18F4550 and it works OK.



Maybe your library for the version with 18F4550 uses special USB RAM area ....
wich is absolute adresse..
not existing on 18F46K22 , even it has more RAM than 18F4550


Maybe you can compare resulting asm code for both devices .


and on hardware side :
- 3,3V level or 5V level ?
- pull up resitor value on I2C bus SCL & SDA ?


Top
 Profile  
 
PostPosted: 18 Jul 2015 18:34 
Offline

Joined: 03 Sep 2008 16:17
Posts: 818
Quote:
ADCON1 = 0b00001111 ; // Configure AN pins as digital I/O

For those chips, ADCON1 don't set A/N. Use ANSELx only.

_________________
Serge T.
Learning is an endeless process but it must start somewhere!


Top
 Profile  
 
PostPosted: 18 Jul 2015 20:21 
Offline

Joined: 25 Sep 2012 23:51
Posts: 125
Location: Sweden
paulfjujo wrote:
hello,

Quote:
I have moved a library for OLED (SDD1303) from the MPLAB X to mikroC PRO for PIC18F4550 and it works OK.



Maybe your library for the version with 18F4550 uses special USB RAM area ....
wich is absolute adresse..
not existing on 18F46K22 , even it has more RAM than 18F4550


Maybe you can compare resulting asm code for both devices .


and on hardware side :
- 3,3V level or 5V level ?
- pull up resitor value on I2C bus SCL & SDA ?

I use the mikroC PRO I2C library for both µC. and it it is not the graphic lib who is the problem. The program stop on the first attemt to write a command with mikroC I2C lib even whitout any graphic lib.
Look in the header where the problem is. I2C1_Wr(0x78); // ******************This command causes the program to stop.

The OLED is 5V compatibel and the PIC18F46K22 is 5V. Same as 4550


I dont use pullup on PIC18F4550 not even the WPU and not on the PIC18F46K22 either.


Edit: I use mikroC PRO ver 6.0.0. Maybe there is bugg in it. It is eg. impossible to use the command:
SSP1EN_bit = 1 ; or SSP2EN_bit = 1; only use the form SSP1CON1 = 0b00100000 is working. With PIC18F4550 who have only one SPI-module you can use the form SSPEN_bit = 1 ; that is a little bit confusingly?

_________________
Regards

Plain common sense is not very common.


Top
 Profile  
 
PostPosted: 18 Jul 2015 23:14 
Offline

Joined: 25 Sep 2012 23:51
Posts: 125
Location: Sweden
I have now put 6k pullup on SDA/SCL but still not work.

_________________
Regards

Plain common sense is not very common.


Top
 Profile  
 
PostPosted: 19 Jul 2015 11:50 
Offline

Joined: 24 Jun 2007 19:27
Posts: 1067
Location: 01800 St Maurice de Gourdans France
hello
Have you got an other I2C device , as a PCF8754 (8 I/O)
or a LCD I2C , or other ?
to valide the I2C dialogue with 18F46K22..
to separate the causes of problems.

general I2C probleme
or specific due to the OLED display

Test if device is found at the desired adress
to test with your OLED LCD adresse 0x78


void check_device(unsigned short dev_address)
{
I2C1_Start();
 if (I2C1_Wr(dev_address))
 {
  sprintf(txt,"Device at adresse %02X  is not found",dev_address);
   UART1_Write_Text(txt);

 }
 else
 {
  sprintf(txt,"Device at adresse %02X found OK",dev_address);
   UART1_Write_Text(txt);
  }
I2C1_Stop();
 CRLF();
}


example of use with EEPROM and RTC devices

// init
#define DS1307_ADDR 0xD0 // RTC DS1307
#define EEPROM_4K_ADR 0xA0 // EEPROM 24LC32
#define EEPROM_128K_ADR 0xA4 // EEPROM 24FC1026    A2=0 A1=1  B=x
#define LCD_ADDR 0x4E     // PCF8574 on pigboard YwRobot back located  on LCD4x20

//...  in the main program

   I2C1_Init(400000);
   UART1_Write_CText("test presence DS1307: \r\n");
  check_device(DS1307_ADDR)  ;
  UART1_Write_CText("test presence 24LC1026 : \r\n");
  check_device(EEPROM_128K_ADR);
  CRLF();



Top
 Profile  
 
PostPosted: 19 Jul 2015 19:14 
Offline

Joined: 25 Sep 2012 23:51
Posts: 125
Location: Sweden
Unfortunately I have no other I2C devices to test with so that is not possible.

The first test you described :
(if (I2C1_Wr(dev_address)))I think is not necessarily because that is proven by the try to write in the header-file, where it hang: "I2C1_Wr(0x78);"The program i stopped here awaiting for the write attempt ack, but it not arrive.

_________________
Regards

Plain common sense is not very common.


Top
 Profile  
 
PostPosted: 19 Jul 2015 21:27 
Offline

Joined: 03 Sep 2008 16:17
Posts: 818
Are you sure your display is still working? From the datasheet it don't seems that it is 5V compatible. Can you put back the 18F4550 to try?
Attachment:
DC_charact.gif
DC_charact.gif [ 24.77 KiB | Viewed 1992 times ]

_________________
Serge T.
Learning is an endeless process but it must start somewhere!


Top
 Profile  
 
PostPosted: 19 Jul 2015 23:00 
Offline

Joined: 25 Sep 2012 23:51
Posts: 125
Location: Sweden
I dont know where you foud this information. This is the information I have about the OLED.
Quote:
No backlight, the display unit can be self-luminous
High resolution: 128 * 64
Viewing angle:> 160 °
Supports many control chip: Fully compatible with Arduino, 51 series, MSP430 series, STM32 / 2, CSR chip, etc.
Ultra-low power consumption: full screen lit 0.08W, 0.06W normal full-screen display of Chinese characters
Wide voltage support: without any modification, directly supports 3V ~ 5V DC
Working temperature: -30 ℃ ~ 70 ℃
Module volume (generous): 27.0MM * 27.0MM * 4.1MM
Minimum occupancy on Earth IO port display: The IIC/I2C communication, as long as the two IO ports will be able to drive!
Driver IC: SSD1306

Here is a picture on it just this nomen with PIC18F4550. It has been plugged in for 12 hours to test the circuit board now.
Attachment:
Pådrag.jpg
Pådrag.jpg [ 1.42 MiB | Viewed 1987 times ]

_________________
Regards

Plain common sense is not very common.


Top
 Profile  
 
PostPosted: 20 Jul 2015 11:59 
Offline

Joined: 25 Sep 2012 23:51
Posts: 125
Location: Sweden
I have now tryed to shange the PIC18F4550 against a PIC18LF45K50: It is 3.3V but I tested to run PIC18F4550 who is a 5v om 3.3V and it was no problem at all. So what a f..k is the difference between 4550 and 45K50 . I even tryed a
PIC16F887 and it was working. But not these K µC. Is there someting missing in microC?

I was looking at the defs files for PIC18F46K22 who has 2 MSSP-modules.
Here is what I found:
Quote:
File = P18F46K22.C
sbit SSPEN_bit at SSP2CON1.B5;currently
sbit SSPEN_bit at SSP1CON1.B5; ***** missing***

sbit SSPEN_SSP1CON1_bit at SSP1CON1.B5; currently
sbit SSPEN_SSP2CON1_bit at SSP1CON1.B5; ***** missing***

File = P18F46K22.CP
sbit SSPEN_SSP1CON1_bit at SSP1CON1.B5; currently
sbit SSPEN_SSP2CON1_bit at SSP2CON1.B5; ***** missing***

sbit SSPEN_bit at SSP2CON1.B5; currently
sbit SSPEN_bit at SSP1CON1.B5; ***** missing***

I do not know how this is going, but in my eyes, I think it should be called:
sbit SSP2EN_bit at SSP2CON1.B5;
sbit SSP1EN_bit at SSP1CON1.B5;

The REGISTER 15-2 says: SSPxCON1: SSPx CONTROL REGISTER 1
the bit SSPxEN would be be named SSP1EN eller SSP2EN ?

Maybe this is not the reason to the problem but something is not ok.

I have tested the PIC18F4550 even wihtout WUP and changed the clockspeed to 4, 8, 16 MHZ and the I2S klock to 400 kHz and it still working ok. And I run it at 3.3 V still no problem. I don´t want to upgrade it because I read in this forum that it still is some problem with bugs in the latest ver. Someone on the support need to help me out here.

I use mikroC PRO v. 6.0.0 Registrated to Urban Hahne.

_________________
Regards

Plain common sense is not very common.


Top
 Profile  
 
PostPosted: 20 Jul 2015 13:41 
Offline

Joined: 03 Sep 2008 16:17
Posts: 818
Hi Seniorlemuren,

The information I send you before was taken from the SSD1306 datasheet directly. Maybe your display have additional hardware that allows it to be 5V compatible but SSD1306 is not 5V compatible according to the datasheet.

You are lucky I own a similar display with the same controller. I have modify it to be in I2C mode and I've made some test with a PIC18F46K22. I used this kind of level translator to pass from 5V to 3.3V (http://www.ebay.ca/itm/2pcs-4-channel-B ... 4d356b0df0).

I can confirm you that the program do not stop at I2C_Init. Here is a logic analyzer screenshot to demonstrate it. Unfortunately I don't have the library you use so I cannot test the display entirely, but if you can post it I will push the test further to make the display light up and send a picture of it.
Attachment:
screenshot.png
screenshot.png [ 172.01 KiB | Viewed 1966 times ]

_________________
Serge T.
Learning is an endeless process but it must start somewhere!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 8 guests


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 post attachments in this forum

Search for:
Jump to: