Problem EEPROM UNI/O and mcu Pic 18f4520

Author
Kris83_06
New Member
  • Total Posts : 10
  • Reward points : 0
  • Joined: 2017/05/21 11:05:03
  • Location: 0
  • Status: offline
2017/07/31 10:05:29 (permalink)
0

Problem EEPROM UNI/O and mcu Pic 18f4520

Hello,
 
I have a problem with the UNIO/O EEPROM 11AA010 and a PIF 18f4520. I have used the AN in C ("UNIO PIC18.h" and "UNIO PIC Protocol.c". The compiler is XC8 v1.42.
 
I have written with succeed a bytes on the EEPROM and I am abble to read it (Except f I am trying to read some values...). Howeever I can write a word and read it, either the program is waiting for the flag 
 while (PIR1bits.CCP1IF == 0) {}; on the Inputbit or Outputbit function or nothing can be written/readen on the eeprom.
Maybe I have a problem with the timer and the delays but I am not sure :
 
The code is the following :
 


#ifndef __UNIO_PIC18_H
#define __UNIO_PIC18_H

/** C O N S T A N T D E F I N I T I O N S ************************/
#define STARTHDR 0x55 // Define STARTHDR as 0x55
#define SAK 1 // Define SAK as 1
#define NOSAK 0 // Define NOSAK as 0
#define MAK 1 // Define MAK as 1
#define NOMAK 0 // Define NOMAK as 0
#define DEVICE_ADDR 0xA0 // Define DEVICE_ADDR as 0xA0
//#define DEVICE_ADDR 0xA1 // Define DEVICE_ADDR as 0xA1
#define PAGESIZE 16 // 16-byte page size for 11XXXXX

/** B U S F R E Q U E N C Y C A L C U L A T I O N **************/
#define BUSFREQ 75000 // Set desired bus frequency to 75 kHz
#define FCY 16000000 // Set instruction frequency to 10 MHz //Modifié en 16 MHz
#define HALF_PERIOD ((FCY/(2*BUSFREQ))-1)// Timer period calculation

/** C O M M A N D D E F I N I T I O N S **************************/
No changes

/** I / O P I N D E F I N I T I O N S **************************/
No changes

/** T Y P E D E F S ************************************************/
No changes

 
and the main program:

#include "UNIO PIC18.h"
#include <p18f4520.h>

#define _XTAL_FREQ 16000000



/** P R O T O T Y P E S ************************************************/
void init(void); // Init. function


// PIC18F4520 Configuration Bit Settings

// 'C' source line config statements
   
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

// CONFIG1H
#pragma config OSC = INTIO7 // Oscillator Selection bits (Internal oscillator block, CLKO function on RA6, port function on RA7)
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
#pragma config IESO = OFF // Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled)

// CONFIG2L
#pragma config PWRT = ON // Power-up Timer Enable bit (PWRT enabled)
#pragma config BOREN = SBORDIS // Brown-out Reset Enable bits (Brown-out Reset enabled in hardware only (SBOREN is disabled))
#pragma config BORV = 1 // Brown Out Reset Voltage bits ()

// CONFIG2H
#pragma config WDT = OFF // Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit))
#pragma config WDTPS = 128 // Watchdog Timer Postscale Select bits (1:128)

// CONFIG3H
#pragma config CCP2MX = PORTC // CCP2 MUX bit (CCP2 input/output is multiplexed with RC1)
#pragma config PBADEN = OFF // PORTB A/D Enable bit (PORTB<4:0> pins are configured as digital I/O on Reset)
#pragma config LPT1OSC = OFF // Low-Power Timer1 Oscillator Enable bit (Timer1 configured for higher power operation)
#pragma config MCLRE = ON // MCLR Pin Enable bit (MCLR pin enabled; RE3 input pin disabled)

// CONFIG4L
#pragma config STVREN = ON // Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)
#pragma config LVP = OFF // Single-Supply ICSP Enable bit (Single-Supply ICSP disabled)
#pragma config XINST = OFF // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode))

// CONFIG5L
#pragma config CP0 = OFF // Code Protection bit (Block 0 (000800-001FFFh) not code-protected)
#pragma config CP1 = OFF // Code Protection bit (Block 1 (002000-003FFFh) not code-protected)
#pragma config CP2 = OFF // Code Protection bit (Block 2 (004000-005FFFh) not code-protected)
#pragma config CP3 = OFF // Code Protection bit (Block 3 (006000-007FFFh) not code-protected)

// CONFIG5H
#pragma config CPB = OFF // Boot Block Code Protection bit (Boot block (000000-0007FFh) not code-protected)
#pragma config CPD = OFF // Data EEPROM Code Protection bit (Data EEPROM not code-protected)

// CONFIG6L
#pragma config WRT0 = OFF // Write Protection bit (Block 0 (000800-001FFFh) not write-protected)
#pragma config WRT1 = OFF // Write Protection bit (Block 1 (002000-003FFFh) not write-protected)
#pragma config WRT2 = OFF // Write Protection bit (Block 2 (004000-005FFFh) not write-protected)
#pragma config WRT3 = OFF // Write Protection bit (Block 3 (006000-007FFFh) not write-protected)

// CONFIG6H
#pragma config WRTC = OFF // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) not write-protected)
#pragma config WRTB = OFF // Boot Block Write Protection bit (Boot block (000000-0007FFh) not write-protected)
#pragma config WRTD = OFF // Data EEPROM Write Protection bit (Data EEPROM not write-protected)

// CONFIG7L
#pragma config EBTR0 = OFF // Table Read Protection bit (Block 0 (000800-001FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR1 = OFF // Table Read Protection bit (Block 1 (002000-003FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR2 = OFF // Table Read Protection bit (Block 2 (004000-005FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR3 = OFF // Table Read Protection bit (Block 3 (006000-007FFFh) not protected from table reads executed in other blocks)

// CONFIG7H
#pragma config EBTRB = OFF // Boot Block Table Read Protection bit (Boot block (000000-0007FFh) not protected from table reads executed in other blocks)


//const unsigned char stopText[][20] = {"Quitter ?","OK: START","Annuler: STOP",};
//const char stopPos[3] = {0x80,0x94,0xD4}; //D4 //94
//
//const unsigned char canceledText[][20] = {"Traitement","Annulé",};
//const char canceledPos[3] = {0xC5,0x9B,}; //D4 //94
//
//const unsigned char startText[][20] = {"Pause",};
//const char startPos[3] = {0x87,};
//
//const unsigned char endText[][20] = {"Fin de traitement",};
//const char endPos[3] = {0xC1,};

const unsigned char startTextBlink[][20] = {" ",};
char arr[16];


int main(void)
{
    unsigned char setting=0;
// while(1)
// {
        
        initialisation_microcontroleur(); // Initialisation du microcontroleur.
      
        //Test EEPROM UNI/O
        
        static unsigned char i; // Loop counter
    static WORD_one address; // Address value

     init(); // Initialize PIC

    pageBuffer[0] = 0xCC; // Initialize first data byte

    address._word = 0x133; // Set address to 0x133
    ByteWrite(address); // Write 1 byte of data at 0x133
    pageBuffer[0] = 0xFF;
    ByteRead(address); // Read 1 byte of data at 0x133

    for (i = 0; i < PAGESIZE; i++) // Initialize data array
    {
        pageBuffer[i] = i;
    }

    address._word = 0x150; // Set address to 0x150
    PageWrite(address, PAGESIZE); // Write 1 page of data starting at 0x150
    for (i = 0; i < PAGESIZE; i++) // Initialize data array
    {
        pageBuffer[i] = 0xFF;
    }
    SeqRead(address, PAGESIZE); // Read 1 page of data starting at 0x150
    while(1){}; 
}


void init(void)
{
    // Initialize PLL
    OSCTUNEbits.PLLEN = 1; // Enable PLL
    //Delay100TCYx(200); // Delay for max 2 ms PLL lock time
    __delay_ms(2);
    // Initialize I/O
    ADCON1 = 0x0F; // Configure digital I/O
    SCIO = 0; // Set SCIO to drive low
    SCIOTRIS = 0; // Configure SCIO to output
    Nop(); // Delay to ensure minimum pulse width of 200 ns
    SCIO = 1; // Bring SCIO high to release from POR
    // Initialize Timer1
    T1CON = 0b10000000; // Configure Timer1, 1:1 prescalar, 16-bit
    CCPR1H = 0x00; // Clear CCPR1H
    CCPR1L = HALF_PERIOD; // Load HALF_PERIOD into CCPR1L
    TMR1H = 0x00; // Clear TMR1H
    TMR1L = 0x00; // Clear TMR1L
    // Initialize CCP1
    CCP1CON = 0b00001011; // Configure special event trigger

    StandbyPulse(); // Generate Standby Pulse
} // end init(void)

 
Thank you for your help,
 
Kris
#1

1 Reply Related Threads

    Kris83_06
    New Member
    • Total Posts : 10
    • Reward points : 0
    • Joined: 2017/05/21 11:05:03
    • Location: 0
    • Status: offline
    Re: Problem EEPROM UNI/O and mcu Pic 18f4520 2017/08/01 04:49:57 (permalink)
    3 (2)
    Hello,
     
    I think I have found the problem. It's due to the delays and the HALF PERIOD time in relation with the bus frequency. For the mcu 18 MHz, I set the Bus frequency on 50 MHz and the frequency on 16 MHz.
     
    I hope it helps,
     
    Kris
    #2
    Jump to:
    © 2018 APG vNext Commercial Version 4.5