Autor Tema: CUIDADO Con los PIC familia K40  (Leído 1710 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado f-traxx

  • Colaborador
  • PIC16
  • *****
  • Mensajes: 116
CUIDADO Con los PIC familia K40
« en: 20 de Diciembre de 2017, 14:11:37 »
Bunenas!

No se si alguien ha trasteado con los PIC K40. Yo si, en mi caso con el PIC18F67K40. Debido a mi experiencia quería advertir que se debe andar con ojo con ellos. Tienen errores de sílice muy severos relacionados con el NVMREG. Es muy importante leer el ERRATA de esta familia http://ww1.microchip.com/downloads/en/DeviceDoc/80000715C.pdf

Error:
Citar
TBLRD requires NVMREG value to point to
appropriate memory
The affected silicon revisions of the PIC18FXXK40
devices improperly require the NVMREG<1:0>
bits in the NVMCON register to be set for TBLRD
access of the various memory regions. The issue
is most apparent in compiled C programs when the
user defines a const type and the compiler uses
TBLRD instructions to retrieve the data from
program Flash memory (PFM). The issue is also
apparent when the user defines an array in RAM
for which the complier creates start-up code,
executed before main(), that uses TBLRD
instructions to initialize RAM from PFM.

Solución:
Citar
Set the NVMREG<1:0> bits to select the
appropriate memory region before executing
TBLRD instructions.
C code:
Create an assembly file named power-up.as and
include this file with the other files in the project.
This file will change the NVMREG<1:0> bits to
point to program Flash before any code is
executed.
Contents of the powerup.as file:
Código: [Seleccionar]
#include <xc.inc>
GLOBAL powerup, start
PSECT powerup, class=CODE, delta=1,
reloc=2
powerup:
BSF NVMCON1, 7
GOTO start
end
If there is a need to change the NVMREG<1:0>
value to anything other than ‘10’ and the Interrupt
Service Routine uses constants or literal strings,
then interrupts must be disabled before the
change and restored to ‘10’ before interrupts are
enabled.

En Resumen, para utilizar estos microcontroladores, cuando se quiera escribir en un registro o en otro (EEPROM, FLASH etc..) se debe poner el NVMREG apuntando en el sitio correcto y mas importante todavía, inicializarlo de la manera que indica Microchip con el powerup.as file. Si se utiliza MPLAB X también se puede poner NVMREG en el apartado ERRATA del XC8 linker.

Caso en el que a mi me ha afectado:
Caso:Guardo datos a la EEPROM, y después quiero escribir en el puerto EUSART2 y no me envia nada.
Solución: Modificar la función que proporciona el MCC para escribir en la EEPROM. (Si os la hacéis vosotros, teniendo todos los registros en cuenta supongo que no tendréis problemas)
Código: [Seleccionar]
void DATAEE_WriteByte(uint16_t bAdd, uint8_t bData)
{
    uint8_t GIEBitValue = INTCONbits.GIE;

    NVMADRH = ((bAdd >> 8) & 0x03);
    NVMADRL = (bAdd & 0xFF);
    NVMDAT = bData;
    NVMCON1bits.NVMREG = 0;
   
   
    NVMCON1bits.WREN = 1;
    INTCONbits.GIE = 0;     // Disable interrupts
    NVMCON2 = 0x55;
    NVMCON2 = 0xAA;
    NVMCON1bits.WR = 1;
    // Wait for write to complete
    while (NVMCON1bits.WR)
    {
    }

    NVMCON1bits.NVMREG = 2; //Añadir esto para poder escribir en la Flash Memory
    NVMCON1bits.WREN = 0;
   
    INTCONbits.GIE = GIEBitValue;   // restore interrupt enable
}

Espero que a alguien le sirva de ayuda o le sirva para tenerlo en cuenta cuando empiece un proyecto con esta familia de PICs.

Desconectado KILLERJC

  • Colaborador
  • DsPIC33
  • *****
  • Mensajes: 8242
Re:CUIDADO Con los PIC familia K40
« Respuesta #1 en: 20 de Diciembre de 2017, 14:39:14 »
interesante saberlo, espero que saquen un fix del compilador para que en estas familias se arregle por software estos errores del silicio.


 

anything