TODOPIC

Microcontroladores PIC => Pic32 => Mensaje iniciado por: KALLITOS en 07 de Diciembre de 2014, 04:43:04

Título: Iniciando pic32MZ
Publicado por: KALLITOS en 07 de Diciembre de 2014, 04:43:04
Hola amigos, se está llevando un hilo respecto a los pic32mz y no quiero desvirtuarlo.
Lo que me pasa es que tengo pic32MZ2048ECG100 y no logra hacer que oscile el PORTD.

He probado el multiplicador con varios valores, y nada. Ni siquiera pone el PORTD a cero, es decir no arranca el pic.

Qué debo hacer o en que estoy fallando. El codigo es el siguiente:

Código: C
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <xc.h>
  4.  
  5. #pragma config POSCMOD = OFF // External Clock Mode
  6. #pragma config FNOSC = SPLL // System Clock is through System PLL
  7. #pragma config FPLLICLK = PLL_FRC // Input to PLL is from Primary Oscillator
  8. #pragma config FPLLIDIV = DIV_1 // Divide input by 3
  9. #pragma config FPLLRNG = RANGE_5_10_MHZ // Input to PLL will be in 5-10 MHz range after division
  10. #pragma config FPLLMULT = MUL_10 // Multiply frequency by 50
  11. #pragma config FPLLODIV = DIV_2 // Divide VCO output by
  12. #pragma config FWDTEN = OFF
  13.  
  14.  
  15. int main(int argc, char** argv) {
  16.  
  17.     unsigned short cont = 0;
  18.     unsigned short i = 0;
  19.  
  20.     TRISD = 0;
  21.     LATD = 0;
  22.    
  23.     while(1)
  24.     {
  25.  
  26.         if(++cont > 0xFF)
  27.         {
  28.             cont = 0;
  29.             if(i)
  30.             {
  31.                 LATD = 0;
  32.                 i = 0;
  33.             }
  34.             else
  35.             {
  36.                 LATD = 0xFFFF;
  37.                 i = 1;
  38.             }
  39.         }
  40.     }
  41.     return (EXIT_SUCCESS);
  42. }

(https://fbcdn-sphotos-g-a.akamaihd.net/hphotos-ak-xfa1/v/t1.0-9/10291235_733689043374588_7594073784473563057_n.jpg?oh=91e46faf6643cf511ba36f2fe44ce45d&oe=5547D1EB&__gda__=1427690461_bd975ae4a260848382dc7144e6d65537)
(https://scontent-a-mia.xx.fbcdn.net/hphotos-xaf1/v/t1.0-9/10435541_733688860041273_7080210560245560406_n.jpg?oh=da536415159e328359e050e470aaa068&oe=551C1BFD)
(https://scontent-a-mia.xx.fbcdn.net/hphotos-xpa1/v/t1.0-9/10685560_733688723374620_3837524420500465220_n.jpg?oh=2341f55f2998a293347f6b0a61a03256&oe=551BC827)
Título: Re: Iniciando pic32MZ
Publicado por: KILLERJC en 07 de Diciembre de 2014, 04:53:01
Es la misma version pero con mas memoria que el que esta usando mig, seguro el te lo soluciona xD
Título: Re: Iniciando pic32MZ
Publicado por: migsantiago en 07 de Diciembre de 2014, 14:37:42
Qué tal Kallitos

Qué bien que te aventuraste a aprender con estos micros nuevos.

Un tip... procura usar Harmony para configurar todo. Microchip va a eliminar las librerías PLIB para PIC32 en un rato. Entonces vas a tener que moverte a Harmony de todas formas. Si las usas en tu código, el compilador te avienta un warning con la misma amenaza jeje.

Pero bueno, con tu código aquí los tips:

+ Configura los ANSEL, pull up/down, TRIS, PORTD, estos son los míos...

Código: [Seleccionar]
#define SYS_PORT_D_ANSEL        0x4000
#define SYS_PORT_D_TRIS         0xfe38
#define SYS_PORT_D_ODC          0x0
#define SYS_PORT_D_CNPU         0x1
#define SYS_PORT_D_CNPD         0x0
#define SYS_PORT_D_CNEN         0x0

+ Configura el Peripheral Bus Clock 4, te sugiero que sea al máximo de 100MHz (¿qué veloz no?). Éste sirve para los PORTS. Sí... los GPIO necesitan clock, ¿qué cosas no?

Código: [Seleccionar]
void SYS_CLK_Initialize( const SYS_CLK_INIT const * clkInit )
{
    SYS_DEVCON_SystemUnlock ( );
   
    PLIB_OSC_FRCDivisorSelect( OSC_ID_0, OSC_FRC_DIV_1);
    /* Enable Peripheral Bus 1 */
    PLIB_OSC_PBClockDivisorSet (OSC_ID_0, 0, 2 );
    PLIB_OSC_PBOutputClockEnable (OSC_ID_0, 0 );
    /* Enable Peripheral Bus 2 */
    PLIB_OSC_PBClockDivisorSet (OSC_ID_0, 1, 2 );
    PLIB_OSC_PBOutputClockEnable (OSC_ID_0, 1 );
    /* Enable Peripheral Bus 3 */
    PLIB_OSC_PBClockDivisorSet (OSC_ID_0, 2, 2 );
    PLIB_OSC_PBOutputClockEnable (OSC_ID_0, 2 );
    /* Enable Peripheral Bus 4 */
    PLIB_OSC_PBClockDivisorSet (OSC_ID_0, 3, 2 );
    PLIB_OSC_PBOutputClockEnable (OSC_ID_0, 3 );
    /* Enable Peripheral Bus 5 */
    PLIB_OSC_PBClockDivisorSet (OSC_ID_0, 4, 2 );
    PLIB_OSC_PBOutputClockEnable (OSC_ID_0, 4 );
    /* Enable Peripheral Bus 7 */
    PLIB_OSC_PBClockDivisorSet (OSC_ID_0, 6, 1 );
    PLIB_OSC_PBOutputClockEnable (OSC_ID_0, 6 );
    /* Disable Peripheral Bus 8 */
    PLIB_OSC_PBOutputClockDisable (OSC_ID_0, 7 );

    /* Enable and configure REFCLKO1*/
   
    /* ROSEL System Clock SYSCLK */
    PLIB_OSC_ReferenceOscBaseClockSelect ( OSC_ID_0, 0, 0 );
    /* RODIV */
    PLIB_OSC_ReferenceOscDivisorValueSet ( OSC_ID_0, 0, 10 );
    /* ROTRIM */
    PLIB_OSC_ReferenceOscTrimSet ( OSC_ID_0, 0, 0 );

    PLIB_OSC_ReferenceOscEnable ( OSC_ID_0, 0 );
    /* Disable REFCLK1_OE*/
    PLIB_OSC_ReferenceOutputDisable ( OSC_ID_0, 0 );
    /* Disable REFCLKO2*/
    PLIB_OSC_ReferenceOscDisable ( OSC_ID_0, 1 );
    /* Disable REFCLK2_OE*/
    PLIB_OSC_ReferenceOutputDisable ( OSC_ID_0, 1 );
    /* Disable REFCLKO3*/
    PLIB_OSC_ReferenceOscDisable ( OSC_ID_0, 2 );
    /* Disable REFCLK3_OE*/
    PLIB_OSC_ReferenceOutputDisable ( OSC_ID_0, 2 );
    /* Disable REFCLKO4*/
    PLIB_OSC_ReferenceOscDisable ( OSC_ID_0, 3 );
    /* Disable REFCLK4_OE*/
    PLIB_OSC_ReferenceOutputDisable ( OSC_ID_0, 3 );

    SYS_DEVCON_SystemLock ( );
}

+ Configura tu POSC o FRC correctamente. ¿Estás usando cristal o el FRC interno? Si usas cristal, checa porfas lo del otro hilo (http://www.todopic.com.ar/foros/index.php?topic=43803.msg362906#msg362906).

+ Si es cristal, checa los multiplicadores para que eleves la velocidad del System Clock a 200MHz. Asegúrate de poner una pull-up de 10k en OSC2. A ver si a ti sí te funciona.

+ Si es FRC, eleva los 8MHz a 200MHz para el System Clock. Checa mi adjunto.

+ Configura todos los configuration registers apropiadamente. Son muy parecidos a los PICs de siempre.

Código: [Seleccionar]
/*** DEVCFG0 ***/

#pragma config DEBUG =      OFF
#pragma config JTAGEN =     OFF
#pragma config ICESEL =     ICS_PGx1
#pragma config TRCEN =      ON
#pragma config BOOTISA =    MIPS32
#pragma config FECCCON =    OFF_UNLOCKED
#pragma config FSLEEP =     OFF
#pragma config DBGPER =     PG_ALL
#pragma config EJTAGBEN =   NORMAL
#pragma config CP =         OFF

/*** DEVCFG1 ***/

#pragma config FNOSC =      SPLL
#pragma config DMTINTV =    WIN_127_128
#pragma config FSOSCEN =    OFF
#pragma config IESO =       OFF
#pragma config POSCMOD =    EC
#pragma config OSCIOFNC =   OFF
#pragma config FCKSM =      CSDCMD
#pragma config WDTPS =      PS1048576
#pragma config WDTSPGM =    STOP
#pragma config FWDTEN =     OFF
#pragma config WINDIS =     NORMAL
#pragma config FWDTWINSZ =  WINSZ_25
#pragma config DMTCNT =     DMT31
#pragma config FDMTEN =     OFF

/*** DEVCFG2 ***/

#pragma config FPLLIDIV =   DIV_1
#pragma config FPLLRNG =    RANGE_5_10_MHZ
#pragma config FPLLICLK =   PLL_FRC
#pragma config FPLLMULT =   MUL_50
#pragma config FPLLODIV =   DIV_2
#pragma config UPLLFSEL =   FREQ_24MHZ
#pragma config UPLLEN =     ON

/*** DEVCFG3 ***/

#pragma config USERID =     0xffff
#pragma config FMIIEN =     OFF
#pragma config FETHIO =     OFF
#pragma config PGL1WAY =    ON
#pragma config PMDL1WAY =   OFF
#pragma config IOL1WAY =    OFF
#pragma config FUSBIDIO =   OFF

/*** BF1SEQ0 ***/

#pragma config TSEQ =       0xffff
#pragma config CSEQ =       0xffff

+ Procura usar los typedefs de stdint.h, son más estándar y no te pierdes buscando tamaños de variables...

Código: [Seleccionar]
#ifndef int8_t
typedef __int8_t int8_t;
#define int8_t __int8_t
#endif

#ifndef uint8_t
typedef __uint8_t uint8_t;
#define uint8_t __uint8_t
#endif

#ifndef int16_t
typedef __int16_t int16_t;
#define int16_t __int16_t
#endif

#ifndef uint16_t
typedef __uint16_t uint16_t;
#define uint16_t __uint16_t
#endif

#ifndef int32_t
typedef __int32_t int32_t;
#define int32_t __int32_t
#endif

#ifndef uint32_t
typedef __uint32_t uint32_t;
#define uint32_t __uint32_t
#endif

#ifndef int64_t
typedef __int64_t int64_t;
#define int64_t __int64_t
#endif

#ifndef uint64_t
typedef __uint64_t uint64_t;
#define uint64_t __uint64_t
#endif

#ifndef intptr_t
typedef __intptr_t intptr_t;
#define intptr_t __intptr_t
#endif

#ifndef uintptr_t
typedef __uintptr_t uintptr_t;
#define uintptr_t __uintptr_t
#endif

+ Si usas cristal checa que la R de 1M esté conectada en paralelo al cristal.

+ Puedes medir el System Clock con un truco... usando REFCLKO... lo hice con Harmony, pero ya lo deshabilité. El chiste es que sacas una división del System Clock por un pin del PIC y pues puedes medir el reloj de esa manera. Así es como descubrí que el POSC no me funcionaba.

Y eso es lo que se me ocurre por el momento. Harmony hizo la mayoría por mí, lo bueno es que habiendo ya usado PICs reconozco y entiendo el código que genera... muy rebuscado, pero bueno, lo genera.

Saludos.
Título: Re: Iniciando pic32MZ
Publicado por: migsantiago en 07 de Diciembre de 2014, 14:41:26
Ahhh... y me cuentas cómo te va con la promesa en tu firma...

Citar
A un microcontrolador hay que sacarle hasta el ultimo byte....(YO)

jejej

2MB de ROM... son 2MB de ROM jajaj  :mrgreen:

¡Otro tip!

+ No habilites la optimización más allá de 0... el depurar te va a dar dolores de cabeza.

+ Cuando el POSC no funciona, el micro se auto protege y se mueve al BFRC... es un resonador de backup de 8MHz también... pero imagino que es más inexacto que el FRC.
Título: Re: Iniciando pic32MZ
Publicado por: KALLITOS en 09 de Diciembre de 2014, 16:53:19
Hola migsantiago, muchas gracias por tu respuesta.

Utilicé los fuses que me indicaste, y le hice unas modificaciones para trabajar con el oscilador interno, ya había leído el otro post de pic32MZ y preferí no tomar ese camino.

No uso PLIB, nunca me gustó, prefiero hacer codigo a pulso, no me gusta usar librerías de las que no se como funcionan internamente, prefiero la libertad, jajajaja. Bueno hago esto lo más que pueda, pero cuando ya toca USB le dejo la chamba a microchip.

Estuve viendo Harmony, y opino que microchip nos está encerrando en su mundo, no me gusta para nada, aunque ví que tiene librerías para todo, aun así no va conmigo.

Logré hacer funcionar los puertos, por lo menos el PORTB y D oscilaron los demás no los probé, tengo un analizador y medí hasta 6Mhz, aunque creo que estan a mas frecuencia, el analizador ya no da más.

Probé Timer a 32bits y no me dá muy exacto el tiempo que seteo, con pic24EP me daba menos error.
No he podido hacer trabajar la interrupción, estoy en eso aun.

Probé UART2 y funcionó a la primera.

La verdad es que el código de C30 calzó rápido, no tuve problema.

Logré sacar por un pic el REFCLKO3 y REFCLKO4 con divisor de 100 y me dio 1Mhz, comprobando que el PLL me dá 200Mhz.

Pongo por aca el codigo de lo que voy:
Código: C
  1. /*
  2.  * File:   MAIN_PIC32MZ.c
  3.  * Author: Carlos
  4.  *
  5.  * Created on 8 de diciembre de 2014, 09:57 PM
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <math.h>
  11. #include <xc.h>
  12. #include <sys/attribs.h>
  13.  
  14. #define MIPS    100.0
  15. #define FCY     100000000
  16.  
  17. #define BAUDIOS_9600            9600
  18. #define _9600_BAUDIOS           (FCY/(4*(unsigned long)BAUDIOS_9600))-1
  19.  
  20. #pragma config DEBUG =      OFF
  21. #pragma config JTAGEN =     OFF
  22. #pragma config ICESEL =     ICS_PGx2
  23. #pragma config TRCEN =      ON
  24. #pragma config BOOTISA =    MIPS32
  25. #pragma config FECCCON =    OFF_UNLOCKED
  26. #pragma config FSLEEP =     OFF
  27. #pragma config DBGPER =     PG_ALL
  28. #pragma config EJTAGBEN =   NORMAL
  29. #pragma config CP =         OFF
  30.  
  31. // DEVCFG1
  32.  
  33. #pragma config FNOSC =      SPLL
  34. #pragma config DMTINTV =    WIN_127_128
  35. #pragma config FSOSCEN =    OFF
  36. #pragma config IESO =       OFF
  37. #pragma config POSCMOD =    OFF
  38. #pragma config OSCIOFNC =   OFF
  39. #pragma config FCKSM =      CSDCMD
  40. #pragma config WDTPS =      PS1048576
  41. #pragma config WDTSPGM =    STOP
  42. #pragma config FWDTEN =     OFF
  43. #pragma config WINDIS =     NORMAL
  44. #pragma config FWDTWINSZ =  WINSZ_25
  45. #pragma config DMTCNT =     DMT31
  46. #pragma config FDMTEN =     OFF
  47.  
  48. // DEVCFG2
  49.  
  50. #pragma config FPLLIDIV =   DIV_1
  51. #pragma config FPLLRNG =    RANGE_5_10_MHZ
  52. #pragma config FPLLICLK =   PLL_FRC
  53. #pragma config FPLLMULT =   MUL_50
  54. #pragma config FPLLODIV =   DIV_2
  55. #pragma config UPLLFSEL =   FREQ_24MHZ
  56. #pragma config UPLLEN =     OFF
  57.  
  58. // DEVCFG3
  59.  
  60. #pragma config USERID =     0xffff
  61. #pragma config FMIIEN =     OFF
  62. #pragma config FETHIO =     OFF
  63. #pragma config PGL1WAY =    ON
  64. #pragma config PMDL1WAY =   OFF
  65. #pragma config IOL1WAY =    OFF
  66. #pragma config FUSBIDIO =   OFF
  67.  
  68. // BF1SEQ0
  69.  
  70. #pragma config TSEQ =       0xffff
  71. #pragma config CSEQ =       0xffff
  72.  
  73. char    str_TX_UART[100];
  74.  
  75.  
  76.  
  77. void init_PORTS(void);
  78. void out_CLK(void);
  79. void init_timer32(void);
  80. void __ISR (_TIMER_3_VECTOR, IPL1SRS) Timer3Handler (void);
  81. void calculo_frecuencia(unsigned long val_frec);
  82.  
  83. void UART2Init(unsigned short baudios);
  84. void UART2PutChar( char ch );
  85. void UART2PrintString( char *str );
  86.  
  87. int main() {
  88.  
  89.  
  90.     out_CLK();
  91.     init_PORTS();
  92.     UART2Init(_9600_BAUDIOS);
  93.    
  94.     sprintf(str_TX_UART,"Iniciando Sistema\r\n");UART2PrintString(str_TX_UART);
  95.     sprintf(str_TX_UART,"PIC32MZ2048ECG100 I/PT\r\n");UART2PrintString(str_TX_UART);
  96.     sprintf(str_TX_UART,"Uart2 Init\r\n");UART2PrintString(str_TX_UART);
  97.     sprintf(str_TX_UART,"      9600 Baudios\r\n");UART2PrintString(str_TX_UART);
  98.     sprintf(str_TX_UART,"Timer3 Init\r\n");UART2PrintString(str_TX_UART);
  99.  
  100.     init_timer32();
  101.     calculo_frecuencia(1000000);
  102.  
  103.     //unsigned short  cont_S = 0;
  104.  
  105.     while(1)
  106.     {
  107.        
  108.     if(IFS0bits.T3IF)
  109.         {
  110.         //sprintf(str_TX_UART,"Seg: %5u\r\n",cont_S++);UART2PrintString(str_TX_UART);
  111.         IFS0bits.T3IF   = 0;          
  112.         LATB = ~LATB;
  113.         }//
  114.    
  115.     }//
  116.     return (EXIT_SUCCESS);
  117. }//
  118.  
  119. void init_PORTS(void)
  120. {
  121.     PB4DIVbits.ON           = 1;        ////    CLOCK PB4 ENABLE PARA GPIO's
  122.     PB4DIVbits.PBDIV        = 2;        ////    DIVIDE LOS 200Mhz ENTRE 2 Y LOGRA 100Mhz
  123.  
  124.     ANSELA  = 0;
  125.     ODCA    = 0;
  126.     CNPUA   = 0;
  127.     CNPDA   = 0;
  128.     TRISA   = 0;
  129.     LATA    = 0;
  130.  
  131.     ANSELB  = 0;
  132.     ODCB    = 0;
  133.     CNPUB   = 0;
  134.     CNPDB   = 0;
  135.     TRISB   = 0;
  136.     LATB    = 0;
  137.  
  138.     ANSELC  = 0;
  139.     ODCC    = 0;
  140.     CNPUC   = 0;
  141.     CNPDC   = 0;
  142.     TRISC   = 0;
  143.     LATC    = 0;
  144.  
  145.     ANSELD  = 0;
  146.     ODCD    = 0;
  147.     CNPUD   = 0;
  148.     CNPDD   = 0;
  149.     TRISD   = 0;
  150.     LATD    = 0;
  151.  
  152.     ANSELE  = 0;
  153.     ODCE    = 0;
  154.     CNPUE   = 0;
  155.     CNPDE   = 0;
  156.     TRISE   = 0;
  157.     LATE    = 0;
  158.  
  159.     ANSELF  = 0;
  160.     ODCF    = 0;
  161.     CNPUF   = 0;
  162.     CNPDF   = 0;
  163.     TRISF   = 0;
  164.     LATF    = 0;
  165.  
  166.     ANSELG  = 0;
  167.     ODCG    = 0;
  168.     CNPUG   = 0;
  169.     CNPDG   = 0;
  170.     TRISG   = 0;
  171.     LATG    = 0;
  172. }//
  173.  
  174. void out_CLK(void)
  175. {
  176. RPD2Rbits.RPD2R         = 0b1101;   ////    SALIDA DE REFCLKO4 POR EL PORT D2
  177. //CNCONDbits.ON           = 0;
  178.  
  179. REFO4TRIMbits.ROTRIM    = 0;
  180.  
  181. REFO4CONbits.RODIV      = 100;      ////    DIVIDE LOS 200Mhz PARA OBTENER 1Mhz Y PODER MEDIRLO CON ANALIZADOR
  182. REFO4CONbits.OE         = 1;        ////    OUTPUT ENABLED
  183. REFO4CONbits.ROSEL      = 7;        ////    FUENTE DE CLOCK PLL
  184. REFO4CONbits.ON         = 1;        ////    HABILITADO EN MODULO
  185.  
  186. RPB0Rbits.RPB0R         = 0b1111;   ////    SALIDA DE REFCLKO3 POR EL PORT B0
  187. //CNCONDbits.ON           = 0;
  188.  
  189. REFO3TRIMbits.ROTRIM    = 0;
  190.  
  191. REFO3CONbits.RODIV      = 100;      ////    DIVIDE LOS 200Mhz PARA OBTENER 1Mhz Y PODER MEDIRLO CON ANALIZADOR
  192. REFO3CONbits.OE         = 1;        ////    OUTPUT ENABLED
  193. REFO3CONbits.ROSEL      = 7;        ////    FUENTE DE CLOCK PLL
  194. REFO3CONbits.ON         = 1;        ////    HABILITADO EN MODULO
  195. }
  196.  
  197. void __ISR (_TIMER_3_VECTOR, IPL1SRS) Timer3Handler (void)
  198. {
  199. LATB = ~LATB;
  200. IFS0bits.T3IF   = 0;
  201. }
  202.  
  203. void calculo_frecuencia(unsigned long val_frec)
  204. {
  205. float dato1;
  206. unsigned long   valor_a_cargar;///valor que se usara en carga de timers
  207.  
  208. sprintf(str_TX_UART,"      %u Hz\r\n",val_frec);UART2PrintString(str_TX_UART);
  209.  
  210. dato1 = (float)val_frec;   //paso valores a float
  211. dato1 = 1000000/dato1;
  212.  
  213.  
  214. valor_a_cargar = (unsigned long)dato1;
  215.  
  216. val_frec = 1000000/val_frec;
  217.  
  218.  
  219. val_frec *= MIPS;
  220. val_frec /= 2;
  221. PR2 = val_frec;            ///cargo los 16 bits bajos
  222. PR3 = val_frec>>16;         ///cargo los 16 bits altos
  223. TMR2    = 0;
  224. TMR3    = 0;
  225. }//
  226.  
  227. void init_timer32(void)////timer2 y timer3 forman timer32
  228. {
  229. PB3DIVbits.ON           = 1;        ////    CLOCK PB3 ENABLE PARA TIMER
  230. PB3DIVbits.PBDIV        = 2;        ////    DIVIDE LOS 200Mhz ENTRE 2 Y LOGRA 100Mhz
  231.  
  232. T2CONbits.T32   = 1;            ////habilito timer32 bits
  233. T2CONbits.TGATE = 0;
  234. T2CONbits.TCS   = 0;
  235. T2CONbits.TON   = 1;
  236.  
  237. IFS0bits.T3IF   = 0;         ///limpio el flag de interrupcion
  238. IEC0bits.T3IE   = 0;         ///habilito la interrupcion
  239. }//
  240.  
  241. void UART2Init(unsigned short baudios)
  242. {
  243.     RPB2Rbits.RPB2R         = 0b0010;   ////    PPS UART2TX
  244.     PB2DIVbits.ON           = 1;        ////    CLOCK PB2 ENABLE PARA UART
  245.     PB2DIVbits.PBDIV        = 2;        ////    DIVIDE LOS 200Mhz ENTRE 2 Y LOGRA 100Mhz
  246.  
  247.     U2BRG = baudios;
  248.     U2MODE = 0;
  249.     U2MODEbits.BRGH = 1;
  250.     U2STA = 0;
  251.     U2MODEbits.UARTEN = 1;
  252.     U2STAbits.UTXEN = 1;
  253.     //_U2RXIF = 0;
  254. }//
  255.  
  256. void UART2PrintString( char *str )
  257. {
  258.     unsigned char c;
  259.  
  260.     while( (c = *str++) )
  261.         UART2PutChar(c);
  262. }//
  263.  
  264. void UART2PutChar( char ch )
  265. {
  266.     U2TXREG = ch;
  267.         Nop();
  268.     while(U2STAbits.TRMT == 0);
  269. }//

Aqui se vé 1Mhz de salida de REFCLKO en el canal 6 en los demas un LATB = ~LATB;

(https://fbcdn-sphotos-d-a.akamaihd.net/hphotos-ak-xpa1/v/t1.0-9/10847879_735027429907416_8041994736074822507_n.jpg?oh=f5ace5a767b858283ced1af28a3b51e2&oe=55022ECB&__gda__=1427123059_09786eecef32e1ec6e5a6b39b003ec85)

Y aca pues me aproveche del Harmony para setear registros y obtener la frecuencia de referencia en un pin.

(https://scontent-a-lga.xx.fbcdn.net/hphotos-xap1/v/t1.0-9/10606097_735027396574086_6883799941320835457_n.jpg?oh=8e78111b93987235f5b05007d2f00acb&oe=550F68C5)

Con respecto a lo de mi firma, es justo por eso que necesito usar este micro, por los 2MB de flash que trae, usé un pic24EP512GU810 de 512 KB y me quedé corto de ROM, ojalá pueda usar toda la memoria sin retricciones.

Lo de la optimización no lahe movido, esta en 0.

Debugear con pickit3 es muy pesado y lento, menos mal ya me funcionó la UART con esta ya puedo saber como van las operaciones y registros.

Continúo mi camino, si hay algo en que te pueda ayudar me avisas mig.

Saludos.
Título: Re: Iniciando pic32MZ
Publicado por: KILLERJC en 09 de Diciembre de 2014, 18:20:39
Interesante :)

Que manera de tener que configurar cosas para el PLL :/, ademas tenes como 8 bus de clock uno para cada cosa, para programarlo terminas con un alto de hoja al lado de la PC para tener todo a mano.

Citar
No uso PLIB, nunca me gustó, prefiero hacer codigo a pulso, no me gusta usar librerías de las que no se como funcionan internamente, prefiero la libertad, jajajaja. Bueno hago esto lo más que pueda, pero cuando ya toca USB le dejo la chamba a microchip.

Estuve viendo Harmony, y opino que microchip nos está encerrando en su mundo, no me gusta para nada, aunque ví que tiene librerías para todo, aun así no va conmigo.

Si es lo que me molesta un poco a mi tambien.
Lo de las librerias yo soy feliz que esten o hacer una de las mias con referencias a esas siempre y cuando pueda ver que es lo que hace dentro de las mismas, es decir que registros cargan, como lo cargan, etc etc etc. Creo que eso es vital, sino ante cualquier problema no sabes como solucionarlo y terminas arrancandote los pelos y finalmente haciendote una libreria vos mismo.
Título: Re: Iniciando pic32MZ
Publicado por: migsantiago en 09 de Diciembre de 2014, 19:15:11
Muy bien Kallitos. Qué bueno que modificas cosas a mano.

Yo empecé con Harmony por la facilidad de configuración en unas cosas, pero la SD library no la pude compilar.

Hay un dato importante que olvidé mencionar en mi mensaje... debes habilitar la pre-caché. La ROM es más lenta que el reloj del CPU. La prechaché agiliza esa situación. Checa los ejemplos de Harmony... se llama devCon_Precache algo así... así volará más rápido tu micro.

Gracias, por ahora no he encontrado más issues en el micro... todo normal... jejej  :mrgreen:
Título: Re: Iniciando pic32MZ
Publicado por: KALLITOS en 10 de Diciembre de 2014, 11:19:43
Bueno estoy detenido, no puedo hacer funcionar las interrupciones, ya probé con Timer3 y Uart2, no funcionan.

Ya puse :
Código: C
  1. INTCONbits.MVEC = 1;    /// MULTIVECTOR INTERRUPCIONES

Y nada, viendo el pdf pic32MZ encontré esto:

CONFIG3
bit 6 VEIC: External Vector Interrupt Controller bit
1 = Support for an external interrupt controller is implemented.
bit 5 VINT: Vector Interrupt bit
1 = Vector interrupts are implemented

Y no lo puedo modificar, ando buscando en fuses, y nada, no lo encuentro, me echan una mano.

saludos.

Edito: Son registros de sólo lectura.
Título: Re: Iniciando pic32MZ
Publicado por: KALLITOS en 10 de Diciembre de 2014, 11:59:57
Hay un dato importante que olvidé mencionar en mi mensaje... debes habilitar la pre-caché. La ROM es más lenta que el reloj del CPU. La prechaché agiliza esa situación. Checa los ejemplos de Harmony... se llama devCon_Precache algo así... así volará más rápido tu micro.

Código: C
  1. PRECONbits.PFMWS    = 2;    ///2 ESTADOS DE ESPERA PARA CACHE SEGUN TABLA 36-13  PIC32MZ 166 < SYSCLK <= 200
  2.     PRECONbits.PREFEN   = 2;
  3.     /*  11 = Enable predictive prefetch for any address
  4.         10 = Enable predictive prefetch for CPU instructions and CPU data
  5.         01 = Enable predictive prefetch for CPU instructions only
  6.         00 = Disable predictive prefetch
  7.      */

Hecho.
Título: Re: Iniciando pic32MZ
Publicado por: KALLITOS en 10 de Diciembre de 2014, 16:44:18
Interrupción Timer2+3  y 4+5  ya estan trabajando.
Ahora Interrupción UART2, que aun no quiere.
Título: Re: Iniciando pic32MZ
Publicado por: KALLITOS en 11 de Diciembre de 2014, 12:47:16
Bueno voy avanzando de a pocos aunque continúa la interrupción UART sin funcionar:

No salta al codigo de interrupción, más el flag si se activa, no sé que mas modificar para que funcione.

pego codigo por si a alguien lo usa.

Código: C
  1. /*
  2.  * File:   MAIN_PIC32MZ.c
  3.  * Author: Carlos
  4.  *
  5.  * Created on 8 de diciembre de 2014, 09:57 PM
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <math.h>
  11.  
  12. #include <xc.h>
  13. #include <proc/p32mz2048ecg100.h>
  14. #include <sys/attribs.h>
  15. #include <stdint.h>
  16.  
  17.  
  18. #define MIPS    100.0
  19. #define FCY     100000000
  20.  
  21. #define BAUDIOS_9600            9600
  22. #define _9600_BAUDIOS           (FCY/(4*(unsigned long)BAUDIOS_9600))-1
  23.  
  24. #pragma config DEBUG =      OFF
  25. #pragma config JTAGEN =     OFF
  26. #pragma config ICESEL =     ICS_PGx2
  27. #pragma config TRCEN =      ON
  28. #pragma config BOOTISA =    MIPS32
  29. #pragma config FECCCON =    OFF_UNLOCKED
  30. #pragma config FSLEEP =     OFF
  31. #pragma config DBGPER =     PG_ALL
  32. #pragma config EJTAGBEN =   NORMAL
  33. #pragma config CP =         OFF
  34.  
  35. // DEVCFG1
  36.  
  37. #pragma config FNOSC =      SPLL
  38. #pragma config DMTINTV =    WIN_127_128
  39. #pragma config FSOSCEN =    OFF
  40. #pragma config IESO =       OFF
  41. #pragma config POSCMOD =    OFF
  42. #pragma config OSCIOFNC =   OFF
  43. #pragma config FCKSM =      CSDCMD
  44. #pragma config WDTPS =      PS1048576
  45. #pragma config WDTSPGM =    STOP
  46. #pragma config FWDTEN =     OFF
  47. #pragma config WINDIS =     NORMAL
  48. #pragma config FWDTWINSZ =  WINSZ_25
  49. #pragma config DMTCNT =     DMT31
  50. #pragma config FDMTEN =     OFF
  51.  
  52. // DEVCFG2
  53.  
  54. #pragma config FPLLIDIV =   DIV_1
  55. #pragma config FPLLRNG =    RANGE_5_10_MHZ
  56. #pragma config FPLLICLK =   PLL_FRC
  57. #pragma config FPLLMULT =   MUL_50
  58. #pragma config FPLLODIV =   DIV_2
  59. #pragma config UPLLFSEL =   FREQ_24MHZ
  60. #pragma config UPLLEN =     OFF
  61.  
  62. // DEVCFG3
  63.  
  64. #pragma config USERID =     0xffff
  65. #pragma config FMIIEN =     OFF
  66. #pragma config FETHIO =     OFF
  67. #pragma config PGL1WAY =    ON
  68. #pragma config PMDL1WAY =   OFF
  69. #pragma config IOL1WAY =    OFF
  70. #pragma config FUSBIDIO =   OFF
  71.  
  72. // BF1SEQ0
  73.  
  74. #pragma config TSEQ =       0xffff
  75. #pragma config CSEQ =       0xffff
  76.  
  77. unsigned char contador = 0;
  78. char str_TX_UART[100];
  79. unsigned char flag_T3 = 0;
  80. unsigned char flag_T5 = 0;
  81. unsigned char flag_T7 = 0;
  82. unsigned char flag_T9 = 0;
  83. unsigned char flag_U2 = 0;
  84. unsigned char dat_U2 = 0;
  85. unsigned char flag_Iext0 = 0;
  86. unsigned char flag_Iext1 = 0;
  87. unsigned char flag_Iext2 = 0;
  88. unsigned char flag_Iext3 = 0;
  89. unsigned char flag_Iext4 = 0;
  90.  
  91. void code_basura(void);
  92. void init_PORTS(void);
  93. void out_CLK(void);
  94. void init_timer32(void);
  95. //void __attribute__((vector(_TIMER_3_VECTOR), interrupt(ipl1), nomips16)) Timer3Handler(void);
  96. void __ISR(_TIMER_3_VECTOR, ipl1) T3_Interrupt(void);
  97. //void __ISR_AT_VECTOR(_TIMER_3_VECTOR, ipl3) T3_Interrupt(void);
  98. void calculo_frecuencia(unsigned int val_frec);
  99.  
  100. //void __attribute__((vector(_UART2_RX_VECTOR), interrupt(ipl1), nomips16)) U2RXHandler(void);//
  101. void __ISR(_UART2_RX_VECTOR, ipl1)U2RXHandler(void);
  102. void UART2Init(unsigned short baudios);
  103. void UART2PutChar(char ch);
  104. void UART2PrintString(char *str);
  105.  
  106. //void __attribute__((vector(_TIMER_5_VECTOR), interrupt(ipl1), nomips16)) Timer5Handler(void);
  107. void __ISR(_TIMER_5_VECTOR, ipl1) T5_Interrupt(void);
  108. void TimerInit(void);
  109.  
  110. void __ISR(_TIMER_7_VECTOR, ipl1) T7_Interrupt(void);
  111. void __ISR(_TIMER_9_VECTOR, ipl1) T9_Interrupt(void);
  112. void __ISR(_EXTERNAL_2_VECTOR, ipl1) Int2_Interrupt(void);
  113. void init_IExt0(void);
  114. void init_IExt1(void);
  115. void init_IExt2(void);
  116. void init_IExt3(void);
  117. void init_IExt4(void);
  118.  
  119. int main() {
  120.  
  121.     //    PB7DIVbits.ON           = 1;        ////    CLOCK PB3 ENABLE PARA TIMER
  122.     //    PB7DIVbits.PBDIV        = 2;        ////    DIVIDE LOS 200Mhz ENTRE 2 Y LOGRA 100Mhz
  123.  
  124.     PRECONbits.PFMWS = 2; ///2 ESTADOS DE ESPERA PARA CACHE SEGUN TABLA 36-13  PIC32MZ 166 < SYSCLK <= 200
  125.     PRECONbits.PREFEN = 2;
  126.     /*  11 = Enable predictive prefetch for any address
  127.         10 = Enable predictive prefetch for CPU instructions and CPU data
  128.         01 = Enable predictive prefetch for CPU instructions only
  129.         00 = Disable predictive prefetch
  130.      */
  131.  
  132.  
  133.     out_CLK();
  134.     init_PORTS();
  135.     UART2Init(_9600_BAUDIOS);
  136.  
  137.     sprintf(str_TX_UART, "Iniciando Sistema\r\n");
  138.     UART2PrintString(str_TX_UART);
  139.     sprintf(str_TX_UART, "PIC32MZ2048ECG100 I/PT\r\n");
  140.     UART2PrintString(str_TX_UART);
  141.     sprintf(str_TX_UART, "Uart2 Init\r\n");
  142.     UART2PrintString(str_TX_UART);
  143.     sprintf(str_TX_UART, "      9600 Baudios\r\n");
  144.     UART2PrintString(str_TX_UART);
  145.     sprintf(str_TX_UART, "Timer3 Init\r\n");
  146.     UART2PrintString(str_TX_UART);
  147.  
  148.  
  149.     init_timer32();
  150.     calculo_frecuencia(10);
  151.  
  152.     TimerInit();
  153.  
  154.     PR4 = PR2; // Period register
  155.     PR5 = PR3; // Period register
  156.  
  157.     PR6 = PR2; // Period register
  158.     PR7 = PR3; // Period register
  159.  
  160.     PR8 = PR2; // Period register
  161.     PR9 = PR3; // Period register
  162.  
  163.     init_IExt0();
  164.     init_IExt1();
  165.     init_IExt2();
  166.     init_IExt3();
  167.     init_IExt4();
  168.    
  169.  
  170.    
  171.     INTCONbits.MVEC = 1; /// MULTIVECTOR INTERRUPCIONES
  172.     __builtin_enable_interrupts();
  173.  
  174.     while (1) {
  175.      
  176.        
  177.         if(IFS4bits.U2RXIF) {   ///CODGIO QUE SE EJECUTA DIRECTAMENTE SIN EJECUTAR CODIGO DE INTERRUPCION
  178.             sprintf(str_TX_UART, "UART: %c\r\n",U2RXREG);UART2PrintString(str_TX_UART);
  179.             IFS4bits.U2RXIF = 0;
  180.             }        
  181.  
  182.         if (flag_U2) {      ///CODIGO QUE DEBE EJECUTARSE RESULTADO DEL CODIGO DE LA INTERRUPCION
  183.             flag_U2 = 0;
  184.             sprintf(str_TX_UART, "UART: \r\n");UART2PrintString(str_TX_UART);
  185.         }
  186.  
  187.         if (flag_T3) {
  188.             flag_T3 = 0;
  189.             sprintf(str_TX_UART, "Timer 3\r\n");
  190.             UART2PrintString(str_TX_UART);
  191.         }//
  192.  
  193.         if (flag_T5) {
  194.             flag_T5 = 0;
  195.             sprintf(str_TX_UART, "Timer 5\r\n");
  196.             UART2PrintString(str_TX_UART);
  197.         }//
  198.         if (flag_T7) {
  199.             flag_T7 = 0;
  200.             sprintf(str_TX_UART, "Timer 7\r\n");
  201.             UART2PrintString(str_TX_UART);
  202.         }//
  203.         if (flag_T9) {
  204.             flag_T9 = 0;
  205.             sprintf(str_TX_UART, "Timer 9\r\n");
  206.             UART2PrintString(str_TX_UART);
  207.         }//
  208.  
  209.         if (flag_Iext0) {
  210.             flag_Iext0 = 0;
  211.             sprintf(str_TX_UART, "IEXT0\r\n");
  212.             UART2PrintString(str_TX_UART);
  213.         }
  214.  
  215.         if (flag_Iext1) {
  216.             flag_Iext1 = 0;
  217.             sprintf(str_TX_UART, "IEXT1\r\n");
  218.             UART2PrintString(str_TX_UART);
  219.         }
  220.  
  221.         if (flag_Iext2) {
  222.             flag_Iext2 = 0;
  223.             sprintf(str_TX_UART, "IEXT2\r\n");
  224.             UART2PrintString(str_TX_UART);
  225.         }
  226.  
  227.         if (flag_Iext3) {
  228.             flag_Iext3 = 0;
  229.             sprintf(str_TX_UART, "IEXT3\r\n");
  230.             UART2PrintString(str_TX_UART);
  231.         }
  232.  
  233.         if (flag_Iext4) {
  234.             flag_Iext4 = 0;
  235.             sprintf(str_TX_UART, "IEXT4\r\n");
  236.             UART2PrintString(str_TX_UART);
  237.         }
  238.  
  239.     }//
  240.     return (EXIT_SUCCESS);
  241. }//
  242.  
  243. void code_basura(void)      ///CODIGO USADO PARA CUANDO HAY POCAS INSTRUCCIONES EN MAIN PRINCIPAL, LAS INTERRUPCIONES PUEDAN EJECUTARSE NORMALMENTE
  244. {
  245. switch (contador) {
  246.                 /////contador = 0;
  247.             case 0:contador++;
  248.                 break;
  249.             case 1:contador++;
  250.                 break;
  251.             case 2:contador++;
  252.                 break;
  253.             case 3:contador++;
  254.                 break;
  255.             case 4:contador++;
  256.                 break;
  257.             case 5:contador++;
  258.                 break;
  259.             case 6:contador++;
  260.                 break;
  261.             case 7:contador++;
  262.                 break;
  263.             case 8:contador++;
  264.                 break;
  265.             case 9:contador++;
  266.                 break;
  267.             case 10:contador++;
  268.                 break;
  269.             case 11:contador++;
  270.                 break;
  271.             case 12:contador++;
  272.                 break;
  273.             case 13:contador++;
  274.                 break;
  275.             case 14:contador++;
  276.                 break;
  277.             case 15:contador++;
  278.                 break;
  279.             case 16:contador++;
  280.                 break;
  281.             case 17:contador++;
  282.                 break;
  283.             case 18:contador++;
  284.                 break;
  285.             case 19:contador++;
  286.                 break;
  287.             case 20:contador++;
  288.                 break;
  289.             case 21:contador++;
  290.                 break;
  291.             case 22:contador++;
  292.                 break;
  293.             case 23:contador = 0;
  294.                 break;
  295.         }
  296.  
  297. }
  298.  
  299.  
  300. void init_PORTS(void) {
  301.     PB4DIVbits.ON = 1; ////    CLOCK PB4 ENABLE PARA GPIO's
  302.     PB4DIVbits.PBDIV = 2; ////    DIVIDE LOS 200Mhz ENTRE 2 Y LOGRA 100Mhz
  303.  
  304.     ANSELA = 0;
  305.     ODCA = 0;
  306.     CNPUA = 0;
  307.     CNPDA = 0;
  308.     TRISA = 0;
  309.     LATA = 0;
  310.  
  311.     ANSELB = 0;
  312.     ODCB = 0;
  313.     CNPUB = 0;
  314.     CNPDB = 0;
  315.     TRISB = 0;
  316.     LATB = 0;
  317.  
  318.     ANSELC = 0;
  319.     ODCC = 0;
  320.     CNPUC = 0;
  321.     CNPDC = 0;
  322.     TRISC = 0;
  323.     LATC = 0;
  324.  
  325.     ANSELD = 0;
  326.     ODCD = 0;
  327.     CNPUD = 0;
  328.     CNPDD = 0;
  329.     TRISD = 0;
  330.     LATD = 0;
  331.  
  332.     ANSELE = 0;
  333.     ODCE = 0;
  334.     CNPUE = 0;
  335.     CNPDE = 0;
  336.     TRISE = 0;
  337.     LATE = 0;
  338.  
  339.     ANSELF = 0;
  340.     ODCF = 0;
  341.     CNPUF = 0;
  342.     CNPDF = 0;
  343.     TRISF = 0;
  344.     LATF = 0;
  345.  
  346.     ANSELG = 0;
  347.     ODCG = 0;
  348.     CNPUG = 0;
  349.     CNPDG = 0;
  350.     TRISG = 0;
  351.     LATG = 0;
  352. }//
  353.  
  354. void out_CLK(void) {
  355.     RPD2Rbits.RPD2R = 0b1101; ////    SALIDA DE REFCLKO4 POR EL PORT D2
  356.     //CNCONDbits.ON           = 0;
  357.  
  358.     REFO4TRIMbits.ROTRIM = 0;
  359.  
  360.     REFO4CONbits.RODIV = 100; ////    DIVIDE LOS 200Mhz PARA OBTENER 1Mhz Y PODER MEDIRLO CON ANALIZADOR
  361.     REFO4CONbits.OE = 1; ////    OUTPUT ENABLED
  362.     REFO4CONbits.ROSEL = 7; ////    FUENTE DE CLOCK PLL
  363.     REFO4CONbits.ON = 1; ////    HABILITADO EN MODULO
  364.  
  365.     RPB0Rbits.RPB0R = 0b1111; ////    SALIDA DE REFCLKO3 POR EL PORT B0
  366.     //CNCONDbits.ON           = 0;
  367.  
  368.     REFO3TRIMbits.ROTRIM = 0;
  369.  
  370.     REFO3CONbits.RODIV = 100; ////    DIVIDE LOS 200Mhz PARA OBTENER 1Mhz Y PODER MEDIRLO CON ANALIZADOR
  371.     REFO3CONbits.OE = 1; ////    OUTPUT ENABLED
  372.     REFO3CONbits.ROSEL = 7; ////    FUENTE DE CLOCK PLL
  373.     REFO3CONbits.ON = 1; ////    HABILITADO EN MODULO
  374. }
  375.  
  376. void __ISR(_TIMER_3_VECTOR, ipl1) T3_Interrupt(void) {
  377.     flag_T3 = 1;
  378.     IFS0bits.T3IF = 0;
  379. }
  380.  
  381. void __ISR(_UART2_RX_VECTOR, ipl1)U2RXHandler(void) {
  382.     flag_U2 = 1; //
  383.     U2TXREG = U2RXREG; //while(!U2STAbits.TRMT); flag_U2 = 1;
  384.     IFS4bits.U2RXIF = 0;
  385. }
  386.  
  387. void calculo_frecuencia(unsigned int val_frec) {
  388.     if (!val_frec)val_frec = 1;
  389.     sprintf(str_TX_UART, "      %u Hz\r\n", val_frec);
  390.     UART2PrintString(str_TX_UART);
  391.     val_frec = 1000000 / val_frec;
  392.     val_frec *= MIPS;
  393.     val_frec *= 10;
  394.  
  395.     sprintf(str_TX_UART, "val_frec %u\r\n", val_frec);
  396.     UART2PrintString(str_TX_UART);
  397.  
  398.     PR2 = val_frec & 0x0000FFFF; ///cargo los 16 bits bajos
  399.     PR3 = (val_frec >> 16) & 0x0000FFFF; ///cargo los 16 bits altos
  400.     TMR2 = 0;
  401.     TMR3 = 0;
  402. }//
  403.  
  404. void init_timer32(void)////timer2 y timer3 forman timer32
  405. {
  406.     PB3DIVbits.ON = 1; ////    CLOCK PB3 ENABLE PARA TIMER
  407.     PB3DIVbits.PBDIV = 2; ////    DIVIDE LOS 200Mhz ENTRE 2 Y LOGRA 100Mhz
  408.  
  409.     T2CONbits.TON = 0; // Stop timer
  410.     T3CONbits.TON = 0; // Stop timer
  411.     TMR2 = 0; // Clear contenst of the TMR4
  412.     T2CONbits.T32 = 1; // 32-bit timer
  413.     T2CONbits.TCKPS = 0; // Divide by 8
  414.     T2CONbits.TCS = 0; // Internal clock
  415.     IPC3bits.T3IP = 1; // Set priority level = 1
  416.     IPC3bits.T3IS = 1; // Set sub-priority level = 1
  417.     IFS0bits.T3IF = 0; // Clear the Timer4 interrupt status flag
  418.     IEC0bits.T3IE = 1; // Enable Timer5 interrupts
  419.     T2CONbits.TON = 1; // Start timer
  420.  
  421.     T6CONbits.TON = 0; // Stop timer
  422.     T7CONbits.TON = 0; // Stop timer
  423.     TMR6 = 0; // Clear contenst of the TMR4
  424.     T6CONbits.T32 = 1; // 32-bit timer
  425.     T6CONbits.TCKPS = 0; // Divide by 8
  426.     T6CONbits.TCS = 0; // Internal clock
  427.     IPC8bits.T7IP = 1; // Set priority level = 1
  428.     IPC8bits.T7IS = 1; // Set sub-priority level = 1
  429.     IFS1bits.T7IF = 0; // Clear the Timer4 interrupt status flag
  430.     IEC1bits.T7IE = 1; // Enable Timer5 interrupts
  431.     T6CONbits.TON = 1; // Start timer
  432.  
  433.     T8CONbits.TON = 0; // Stop timer
  434.     T9CONbits.TON = 0; // Stop timer
  435.     TMR8 = 0; // Clear contenst of the TMR4
  436.     T8CONbits.T32 = 1; // 32-bit timer
  437.     T8CONbits.TCKPS = 0; // Divide by 8
  438.     T8CONbits.TCS = 0; // Internal clock
  439.     IPC10bits.T9IP = 1; // Set priority level = 1
  440.     IPC10bits.T9IS = 1; // Set sub-priority level = 1
  441.     IFS1bits.T9IF = 0; // Clear the Timer4 interrupt status flag
  442.     IEC1bits.T9IE = 1; // Enable Timer5 interrupts
  443.     T8CONbits.TON = 1; // Start timer
  444. }//
  445.  
  446. void UART2Init(unsigned short baudios) {
  447.     TRISDbits.TRISD4 = 1;
  448.  
  449.     RPB2Rbits.RPB2R = 0b0010; ////    PPS UART2TX
  450.     U2RXRbits.U2RXR = 0b0100; ////    RX2 EN PIND4
  451.  
  452.     PB2DIVbits.ON = 1; ////    CLOCK PB2 ENABLE PARA UART
  453.     PB2DIVbits.PBDIV = 2; ////    DIVIDE LOS 200Mhz ENTRE 2 Y LOGRA 100Mhz
  454.  
  455.     U2BRG = baudios;
  456.     U2STA = 0;
  457.     U2MODE = 0;
  458.     U2MODEbits.BRGH = 1;
  459.     U2STAbits.URXEN = 1;
  460.     U2STAbits.UTXEN = 1;
  461.     U2STAbits.URXISEL = 0;
  462.  
  463.  
  464.     IPC36bits.U2EIP = 1;
  465.     IPC36bits.U2EIS = 1;
  466.     IFS4bits.U2RXIF = 0;
  467.     IEC4bits.U2RXIE = 1;
  468.  
  469.     U2MODEbits.ON = 1;
  470.  
  471. }//
  472.  
  473. void UART2PrintString(char *str) {
  474.     unsigned char c;
  475.  
  476.     while ((c = *str++))
  477.         UART2PutChar(c);
  478. }//
  479.  
  480. void UART2PutChar(char ch) {
  481.     U2TXREG = ch;
  482.     Nop();
  483.     while (!U2STAbits.TRMT);
  484. }//
  485.  
  486. void TimerInit(void) {
  487.     T4CONbits.TON = 0; // Stop timer
  488.     T5CONbits.TON = 0; // Stop timer
  489.     TMR4 = 0; // Clear contenst of the TMR4
  490.     T4CONbits.T32 = 1; // 32-bit timer
  491.     T4CONbits.TCKPS = 0; // Divide by 8
  492.     PR4 = 1000; // Period register
  493.     T4CONbits.TCS = 0; // Internal clock
  494.     IPC6bits.T5IP = 1; // Set priority level = 1
  495.     IPC6bits.T5IS = 1; // Set sub-priority level = 1
  496.     IFS0bits.T5IF = 0; // Clear the Timer4 interrupt status flag
  497.     IEC0bits.T5IE = 1; // Enable Timer5 interrupts
  498.     //asm volatile("ei"); // Assembler interrupts enable
  499.     T4CONbits.TON = 1; // Start timer
  500. }
  501.  
  502. void __ISR(_TIMER_5_VECTOR, ipl1) T5_Interrupt(void) {
  503.     flag_T5 = 1;
  504.     LATBbits.LATB3 = ~LATBbits.LATB3;
  505.     IFS0bits.T5IF = 0; //Clear flag
  506. }
  507.  
  508. void __ISR(_TIMER_7_VECTOR, ipl1) T7_Interrupt(void) {
  509.     flag_T7 = 1;
  510.     IFS1bits.T7IF = 0; //Clear flag
  511. }
  512.  
  513. void __ISR(_TIMER_9_VECTOR, ipl1) T9_Interrupt(void) {
  514.     flag_T9 = 1;
  515.     IFS1bits.T9IF = 0; //Clear flag
  516. }
  517.  
  518. void __ISR(_EXTERNAL_0_VECTOR, ipl1) Int0_Interrupt(void) {
  519.     flag_Iext0 = 1;
  520.     IFS0bits.INT0IF = 0; //Clear flag
  521. }
  522.  
  523. void __ISR(_EXTERNAL_1_VECTOR, ipl1) Int1_Interrupt(void) {
  524.     flag_Iext1 = 1;
  525.     IFS0bits.INT1IF = 0; //Clear flag
  526. }
  527.  
  528. void __ISR(_EXTERNAL_2_VECTOR, ipl1) Int2_Interrupt(void) {
  529.     flag_Iext2 = 1;
  530.     IFS0bits.INT2IF = 0; //Clear flag
  531. }
  532.  
  533. void __ISR(_EXTERNAL_3_VECTOR, ipl1) Int3_Interrupt(void) {
  534.     flag_Iext3 = 1;
  535.     IFS0bits.INT3IF = 0; //Clear flag
  536. }
  537.  
  538. void __ISR(_EXTERNAL_4_VECTOR, ipl1) Int4_Interrupt(void) {
  539.     flag_Iext4 = 1;
  540.     IFS0bits.INT4IF = 0; //Clear flag
  541. }
  542.  
  543.  
  544.  
  545. void init_IExt0(void) {
  546.     TRISDbits.TRISD0 = 1;
  547.     IPC0bits.INT0IP = 1;
  548.     IPC0bits.INT0IS = 1;
  549.     //INT0Rbits.INT0R = 1; ///PORTG9 ENTRADA INTEX2
  550.     IFS0bits.INT0IF = 0;
  551.     IEC0bits.INT0IE = 1;
  552. }
  553.  
  554. void init_IExt1(void) {
  555.     TRISGbits.TRISG9 = 1;
  556.     IPC2bits.INT1IP = 1;
  557.     IPC2bits.INT1IS = 1;
  558.     INT1Rbits.INT1R = 1; ///PORTG9 ENTRADA INTEX2
  559.     IFS0bits.INT1IF = 0;
  560.     IEC0bits.INT1IE = 1;
  561. }
  562.  
  563. void init_IExt2(void) {
  564.     TRISGbits.TRISG6 = 1;
  565.     IPC3bits.INT2IP = 1;
  566.     IPC3bits.INT2IS = 1;
  567.     INT2Rbits.INT2R = 1; ///PORTG6 ENTRADA INTEX2
  568.     IFS0bits.INT2IF = 0;
  569.     IEC0bits.INT2IE = 1;
  570. }
  571.  
  572. void init_IExt3(void) {
  573.     TRISGbits.TRISG8 = 1;
  574.     IPC4bits.INT3IP = 1;
  575.     IPC4bits.INT3IS = 1;
  576.     INT3Rbits.INT3R = 1; ///PORTG8 ENTRADA INTEX2
  577.     IFS0bits.INT3IF = 0;
  578.     IEC0bits.INT3IE = 1;
  579. }
  580.  
  581. void init_IExt4(void) {
  582.     TRISGbits.TRISG7 = 1;
  583.     IPC5bits.INT4IP = 1;
  584.     IPC5bits.INT4IS = 1;
  585.     INT4Rbits.INT4R = 1; ///PORTG7 ENTRADA INTEX2
  586.     IFS0bits.INT4IF = 0;
  587.     IEC0bits.INT4IE = 1;
  588. }

(https://scontent-b-iad.xx.fbcdn.net/hphotos-xpa1/v/t1.0-9/10858523_735930003150492_8822201023984769176_n.jpg?oh=c2c8def2f8b340272f21ac001aeac88b&oe=5546DAE6)

saludos.
Título: Re: Iniciando pic32MZ
Publicado por: KALLITOS en 11 de Diciembre de 2014, 14:21:27
Ni Uart1 ni Uart2 quieren

Código: C
  1. if(IFS3bits.U1RXIF) {   ///CODGIO QUE SE EJECUTA DIRECTAMENTE SIN EJECUTAR CODIGO DE INTERRUPCION
  2.             sprintf(str_TX_UART, "UART1: %c\r\n",U1RXREG);UART1PrintString(str_TX_UART);
  3.             IFS3bits.U1RXIF = 0;
  4.             }
  5.  
  6.         if(IFS4bits.U2RXIF) {   ///CODGIO QUE SE EJECUTA DIRECTAMENTE SIN EJECUTAR CODIGO DE INTERRUPCION
  7.             sprintf(str_TX_UART, "UART2: %c\r\n",U2RXREG);UART2PrintString(str_TX_UART);
  8.             IFS4bits.U2RXIF = 0;
  9.             }

Pero asi sí van.
Título: Re: Iniciando pic32MZ
Publicado por: KILLERJC en 11 de Diciembre de 2014, 14:36:16
Por que vi que tiene muchos modos de configuracion entre los cuales calcula la posicion del vector, con una base + offset , etc.
Es lo que le llama Multi-Vector mode

Multi-Vector mode – interrupt requests will be serviced at the calculated vector address

Sino inicia en
Single Vector mode – all interrupt requests will be serviced at one vector address (mode out of reset)

por lo que deberias de preguntar si o si cual es el flag, no se si te lo hace el compilador o no, es como si fuera una interrupcion de un pic de gama media/baja.

Probaste de ponerlo en Multi-vector ? es decir habilitar el bit MVEC de INTCON

Citar
To configure the CPU in Single Vector mode, the following CPU registers (Cause and Status) and the INTCON register must be configured as follows:
•EBase ≠ 00000
•IV bit (Cause<23>) = 1
•MVEC bit (INTCON<12>) = 0
•IE bit (Status<0>) = 1
•Bev = 1

Citar
To configure the CPU in Computed Offset mode, the following CPU registers (IntCtl, Cause and Status) and the INTCON register must be configured as follows:
•EBase ≠ 00000
•VS<6:0> bits (IntCtl<9:5> or INTCON<20:16>) ≠ 00000
•IV bit (Cause<23>) = 1
•MVEC bit (INTCON<12>) = 1
•IE bit (Status<

Aunque si fuera esto las demas tampoco andarian, probaste subirle la prioridad?
Título: Re: Iniciando pic32MZ
Publicado por: KALLITOS en 11 de Diciembre de 2014, 14:39:46
Sí ya lo hice, fijate en el código completo que coloqué en la linea 171 alli está habilitado multivector, además las interrupciones: INTEXT0,INTEXT1,INTEXT2,INTEXT3,INTEXT4,T3,T5,T7,yT9 ya estan funcionando al mismo tiempo.

Por eso no entiendo por qué no funciona Uart1 ni Uart2 no he probado aun con mas interrupciones.

saludos.
Título: Re: Iniciando pic32MZ
Publicado por: KALLITOS en 11 de Diciembre de 2014, 14:50:22
Por que vi que tiene muchos modos de configuracion entre los cuales calcula la posicion del vector, con una base + offset , etc.
Es lo que le llama Multi-Vector mode

Multi-Vector mode – interrupt requests will be serviced at the calculated vector address

Sino inicia en
Single Vector mode – all interrupt requests will be serviced at one vector address (mode out of reset)

por lo que deberias de preguntar si o si cual es el flag, no se si te lo hace el compilador o no, es como si fuera una interrupcion de un pic de gama media/baja.

Probaste de ponerlo en Multi-vector ? es decir habilitar el bit MVEC de INTCON

Citar
To configure the CPU in Single Vector mode, the following CPU registers (Cause and Status) and the INTCON register must be configured as follows:
•EBase ≠ 00000
•IV bit (Cause<23>) = 1
•MVEC bit (INTCON<12>) = 0
•IE bit (Status<0>) = 1
•Bev = 1

Citar
To configure the CPU in Computed Offset mode, the following CPU registers (IntCtl, Cause and Status) and the INTCON register must be configured as follows:
•EBase ≠ 00000
•VS<6:0> bits (IntCtl<9:5> or INTCON<20:16>) ≠ 00000
•IV bit (Cause<23>) = 1
•MVEC bit (INTCON<12>) = 1
•IE bit (Status<

Aunque si fuera esto las demas tampoco andarian, probaste subirle la prioridad?

KILLERJC donde puedo encontrar esa documentación que referencias, gracias por tus respuestas.
Título: Re: Iniciando pic32MZ
Publicado por: KILLERJC en 11 de Diciembre de 2014, 15:01:16
Lo que me molesto siempre apartir de los dsPIC es que tiene todos los documentos descentralizados. Antes 1 solo datasheet era suficiente.
Ahora hace uno para toda la familia, y ademas 1 por cada seccion ( que es general para todos los PIC32 ). Entonces te volves loco mirando 3 datasheets a la ves xD

http://www.microchip.com/wwwproducts/Devices.aspx?product=PIC32MZ2048ECG100
En Documentation and Software -> Reference Manual
PIC32 Family Reference Manual, Sect. 08 Interrupts (http://ww1.microchip.com/downloads/en/DeviceDoc/61108G.pdf)
PIC32 Family Reference Manual, Sect. 21 UART (http://ww1.microchip.com/downloads/en/DeviceDoc/61107G.pdf)

Incluso en el de la UART estan todos los pasos a seguir ya sea para transmision o recepcion con interrupcion, pero es masomenos lo que hiciste vos.
Título: Re: Iniciando pic32MZ
Publicado por: KALLITOS en 12 de Diciembre de 2014, 16:45:49
Definitivamente no puedo hacer funcionar la interrupcion UART.

A diferencia del C30 solo hay que habilitar el

Código: C
  1. INTCONbits.MVEC = 1; /// MULTIVECTOR INTERRUPCIONES

De alli todo es lo mismo, no entiendo que mas me falta hacer.

La documentación que colocas la teno guardada en mi disco duro y lo leo cuando voy programando, pero no encuentro la salida.

Título: Re: Iniciando pic32MZ
Publicado por: KALLITOS en 12 de Diciembre de 2014, 17:10:44
Todo empuja a Harmony, hasta en el foro de microchip.
Ta mare  :?
Título: Re: Iniciando pic32MZ
Publicado por: migsantiago en 13 de Diciembre de 2014, 16:15:22
Podrías habilitarla en Harmony y ver las diferencias de código fuente que genera.  8)
Título: Re: Iniciando pic32MZ
Publicado por: KALLITOS en 13 de Diciembre de 2014, 18:14:59
En el Help de Harmony recomienda MPLABX IDE 2.2 o superior, intento descargar el 2.26 que está disponible y después de un rato se cancela y no puedo descargarla.
Ahora eso juega en mi contra, jajajaja  :8} :8} rio para no llorar.
Título: Re: Iniciando pic32MZ
Publicado por: migsantiago en 13 de Diciembre de 2014, 18:42:18
Kallitos, adjunto las diferencias en código fuente que agregó Harmony para darle servicio a las interrupciones. Comprimí el HTML en ZIP.

Saludos.
Título: Re: Iniciando pic32MZ
Publicado por: KALLITOS en 13 de Diciembre de 2014, 22:39:51
Migsantiago muchas gracias por tu apoyo.

Ok, vamos demembrando esta y veremos como va:

Código: C++
  1. 1)   PLIB_USART_BaudRateSet(USART_ID_2, SYS_CLK_PeripheralFrequencyGet(CLK_BUS_PERIPHERAL_2), 38400);
  2. 2)   PLIB_USART_HandshakeModeSelect(USART_ID_2, USART_HANDSHAKE_MODE_FLOW_CONTROL);
  3. 3)   PLIB_USART_OperationModeSelect(USART_ID_2, USART_ENABLE_TX_RX_USED);
  4. 4)   PLIB_USART_LineControlModeSelect(USART_ID_2, USART_8N1);
  5. 5)   PLIB_USART_TransmitterEnable(USART_ID_2);
  6. 6)   PLIB_USART_TransmitterInterruptModeSelect(USART_ID_2, USART_TRANSMIT_FIFO_NOT_FULL);

Vamos por ítems.
1)
Código: C
  1. PB2DIVbits.ON = 1; ////    CLOCK PB2 ENABLE PARA UART
  2. PB2DIVbits.PBDIV = 2; ////    DIVIDE LOS 200Mhz ENTRE 2 Y LOGRA 100Mhz
  3.  
  4. #define BAUDIOS_9600            9600
  5. #define _9600_BAUDIOS           (FCY/(4*(unsigned long)BAUDIOS_9600))-1

2)  Seteado en 0, aunque no es usado:
Código: C
  1. RTSMD: Mode Selection for UxRTS Pin bit
  2. 1 = UxRTS pin is in Simplex mode
  3. 0 = UxRTS pin is in Flow Control mode

3)seteados ambos a 1.
Código: C
  1. URXEN: Receiver Enable bit
  2. 1 = UARTx receiver is enabled. UxRX pin is controlled by UARTx (if ON = 1)
  3. 0 = UARTx receiver is disabled. UxRX pin is ignored by the UARTx module
  4.  
  5. UTXEN: Transmit Enable bit
  6. 1 = UARTx transmitter is enabled. UxTX pin is controlled by UARTx (if ON = 1)
  7. 0 = UARTx transmitter is disabled. Any pending transmission is aborted and buffer is reset

4) seteado a 0.
Código: C
  1. PDSEL<1:0>: Parity and Data Selection bits
  2. 11 = 9-bit data, no parity
  3. 10 = 8-bit data, odd parity
  4. 01 = 8-bit data, even parity
  5. 00 = 8-bit data, no parity

5)Creo que se está repitiendo, en el caso de estar equivocado, la transmisión si funciona, no en modo interrupción, aun no la uso.
Seteado a 1
Código: C
  1. UTXEN: Transmit Enable bit
  2. 1 = UARTx transmitter is enabled. UxTX pin is controlled by UARTx (if ON = 1)
  3. 0 = UARTx transmitter is disabled. Any pending transmission is aborted and buffer is reset

6) No usado ya que no uso transmisión vía interrupción, talvez por alli esté el problema?

Código: C
  1. PLIB_USART_ReceiverEnable(USART_ID_2);
  2. PLIB_USART_ReceiverInterruptModeSelect(USART_ID_2, USART_RECEIVE_FIFO_ONE_CHAR);
  3.  
  4. /* Initialize TX interrupt */
  5. 7)   PLIB_INT_SourceEnable(INT_ID_0, INT_SOURCE_USART_2_TRANSMIT);
  6. 8)   PLIB_INT_VectorPrioritySet(INT_ID_0, INT_VECTOR_UART2_TX, INT_PRIORITY_LEVEL1);
  7. 9)   PLIB_INT_VectorSubPrioritySet(INT_ID_0, INT_VECTOR_UART2_TX, INT_SUBPRIORITY_LEVEL0);
  8.  
  9. /* Initialize RX interrupt */
  10. 10)   PLIB_INT_SourceEnable(INT_ID_0, INT_SOURCE_USART_2_RECEIVE);
  11. 11)   PLIB_INT_VectorPrioritySet(INT_ID_0, INT_VECTOR_UART2_RX, INT_PRIORITY_LEVEL1);
  12. 12)   PLIB_INT_VectorSubPrioritySet(INT_ID_0, INT_VECTOR_UART2_RX, INT_SUBPRIORITY_LEVEL0);
  13.  
  14. /* Initialize Fault interrupt */
  15. 13)   PLIB_INT_SourceEnable(INT_ID_0, INT_SOURCE_USART_2_ERROR);
  16. 14)   PLIB_INT_VectorPrioritySet(INT_ID_0, INT_VECTOR_UART2_FAULT, INT_PRIORITY_LEVEL1);
  17. 15)   PLIB_INT_VectorSubPrioritySet(INT_ID_0, INT_VECTOR_UART2_FAULT, INT_SUBPRIORITY_LEVEL0);

Items del 7 al 9 no usado aun.
10)
Código: C
  1. IEC3bits.U1RXIE = 1;

11)
Código: C
  1. IPC28bits.U1EIP = 2;

12)
Código: C
  1. IPC28bits.U1EIS = 2;

Items del 13 al 15 no usados.

Me pongo con los items no usados.

Gracias mig!!
Título: Re: Iniciando pic32MZ
Publicado por: migsantiago en 14 de Diciembre de 2014, 14:22:07
Oye Kallitos, ¿tienes bien implementados los PPS para el pin RX que debe arrojar la interrución? ¿Se está transmitiendo el byte a ese pin a una velocidad apropiada? Si no fuera una buena velocidad, estaría detonándose la interrupción por falla.
Título: Re: Iniciando pic32MZ
Publicado por: KALLITOS en 14 de Diciembre de 2014, 21:00:45
Bueno ya en casa despues de este fin de semana.

La recepción si me funciona, en el main me detecta el flag de interrupción y puedo leer el UxRXREG, pero no entra en el handler. Por lo dicho el pps, baudios y demás está bien, pero aun asi voy a implementar la interrupción por falla a ver que sale.

saludos.
Título: Re: Iniciando pic32MZ
Publicado por: KALLITOS en 14 de Diciembre de 2014, 21:37:07
Habilitacion de interrupcion FAULT UART
Código: C
  1. ///HABILITACION DE INTERRUPCION DE ERROR
  2.     IFS3bits.U1EIF = 0;
  3.     IEC3bits.U1EIE = 1;
  4.     IPC28bits.U1EIP = 1;
  5.     IPC28bits.U1RXIS = 1;
  6.  
  7.     ///HABILITACION DE INTERRUPCION DE ERROR
  8.     IFS4bits.U2EIF = 0;
  9.     IEC4bits.U2EIE = 1;
  10.     IPC36bits.U2EIP = 1;
  11.     IPC36bits.U2RXIS = 1;

Handler de interrupción.

Código: C
  1. void __ISR(_UART1_FAULT_VECTOR, ipl1)U1RX_error_Handler(void) {
  2.     flag_U1_error = 1; //
  3.     IFS3bits.U1EIF = 0;
  4. }
  5.  
  6. void __ISR(_UART2_FAULT_VECTOR, ipl1)U2RX_error_Handler(void) {
  7.     flag_U2_error = 1; //
  8.     IFS4bits.U2EIF = 0;
  9. }

Codigo para envío por UART de que sucedió error.

Código: C
  1. if (flag_U1_error) {
  2.             flag_U1_error = 0; //
  3.             sprintf(str_TX_UART, "UART1 ERROR!!!\r\n");
  4.             UART2PrintString(str_TX_UART);
  5.         }
  6.  
  7.         if (flag_U2_error) {
  8.             flag_U2_error = 0; //
  9.             sprintf(str_TX_UART, "UART2 ERROR!!!\r\n");
  10.             UART1PrintString(str_TX_UART);
  11.         }

Y qué creen..... nada, sigue igual.

Lo que he notado es que cuando no leo el UxRXREG y envío datos al pic, éste se resetea después de unos cuantos. Pero no salta el error o la interrupción.

Leo el flag de interrupción FAULT en el main, por si anda igual al UART que leyendo el flag en el main si funciona, y nada, no me manda error, y el micro se resetea.

Seguimos por acá.

saludos!!.
Título: Re: Iniciando pic32MZ
Publicado por: KALLITOS en 14 de Diciembre de 2014, 21:51:56
Del pic32mz por el momento sólo me importan las interrupciones de Uart y Timers, y justo uart no jala, no puede ser. :?
Claro está, sus 200Mhz y sus 2MB de flash, ojala que esto último no me juegue mala pasada después.
Título: Re: Iniciando pic32MZ
Publicado por: KALLITOS en 14 de Diciembre de 2014, 22:59:41
He modificado la frecuencia del PBclock y sigue igual.
Título: Re: Iniciando pic32MZ
Publicado por: migsantiago en 15 de Diciembre de 2014, 12:14:29
Kallitos, checa entonces que no esté habilitada la DMA. Checa que la interrupción se detone cuando llegue un byte, no cuando esté a medio llenarse el buffer (creoq ue ya lo hiciste). Checa que el Watchdog y el DeadMan estén deshabilitados.  :mrgreen:
Título: Re: Iniciando pic32MZ
Publicado por: KILLERJC en 15 de Diciembre de 2014, 12:27:47
Kallitos, checa entonces que no esté habilitada la DMA. Checa que la interrupción se detone cuando llegue un byte, no cuando esté a medio llenarse el buffer (creo que ya lo hiciste). Checa que el Watchdog y el DeadMan estén deshabilitados.  :mrgreen:

Igual lo raro es que la interrupcion se dispara. Es decir su flag se activa, pero no procede a enviarlo al vector de interrupcion. Con lo que la configuracion de la UART andaria bien, lo unico que andaria mal es la parte de interrupciones.

Ahora se me ocurre lo siguiente

__ISR(_UART2_RX_VECTOR, ipl1)U2RXHandler

Tiene un offset definido? cuando se carga ese offset a los registros para el calculo de la interrupcion?. Los demas te andan pero jamas definiste un offset ( me refiero a cargarlos dentro del correspondiente registro ).
Podrias quitar casi todo y probar la UART pero con el Single Vector Mode, a lo que me refiero es que probes solo la UART2 asi y si ejecuta la interrupcion entonces no es un fallo de hardware sino un problema en la configuracion del Multi Vector Mode
Título: Re: Iniciando pic32MZ
Publicado por: KALLITOS en 15 de Diciembre de 2014, 13:03:51
Ya descargué MPLABX 2.26 y la cosa sigue igual, he creado un proyecto desde cero por si algo arrastra del 2.10, pero sigue igual.

Voy a probar con Single Vector Mode.
A ver como va.

Gracias por sus respuestas.
Título: Re: Iniciando pic32MZ
Publicado por: migsantiago en 15 de Diciembre de 2014, 13:40:14
Puede que no ayude, pero ya está la v1.34 disponible para XC32.

Está descargable bajo el link de la 1.33, Microchip no actualizó la página frontal.

Saludos.
Título: Re: Iniciando pic32MZ
Publicado por: KALLITOS en 15 de Diciembre de 2014, 14:35:49
Tengo lo último de microchip:
CX32 v1.33
MPLABX v2.26

Y nada  :?

Algo que veo en el cx32 user guide es esto:

Note: For devices that support multiple Instruction Set Architecture (ISA) modes,
there may be a configuration bit that determines which mode the device
uses for an exception/interrupt. If your device is configured to use the
microMIPS ISA on interrupt, be sure to apply the micromips function
attribute to your interrupt function. Consult your the data sheet for your
target device to determine if it supports handling exceptions and interrupts
in an alternate ISA mode.


Código: C
  1. bit 16 ISAONEXC: ISA on Exception bit(1)
  2. 1 = microMIPS&#8482; is used on entrance to an exception vector
  3. 0 = MIPS32&#174; ISA is used on entrance to an exception vector
  4. bit 15-14 ISA<1:0>: Instruction Set Availability bits(1)
  5. 11 = Both MIPS32&#174; and microMIPS&#8482; are implemented; microMIPS&#8482; is used when coming out of reset
  6. 10 = Both MIPS32&#174; and microMIPS&#8482; are implemented; MIPS32&#174; ISA used when coming out of reset

Código: C
  1. #pragma config BOOTISA =    MIPS32

Leí esto en el foro de microchip:

Código: C
  1. void __ISR(_TIMER_2_VECTOR, ipl3) __attribute__((nomips16)) _T2Interrupt(void)

No sé como va eso.

Me gustaría saber donde encontrar las opciones de seteo de los fuses, en el archivo p32mz2048ecg100.h del pic no está, algo que en C30 si se podía encontrar e el archivo del pic.

 :?
Título: Re: Iniciando pic32MZ
Publicado por: migsantiago en 15 de Diciembre de 2014, 16:43:05
Si quieres por la tarde pruebo la interrupción por UART. En mi código no la necesito, por eso no la he probado. Sólo necesito la del timer1, que funciona sin problemas.

Baja la 1.34... por si las dudas...

http://ww1.microchip.com/downloads/en/DeviceDoc/xc32-v1.34-full-install-windows-installer.exe
Título: Re: Iniciando pic32MZ
Publicado por: KALLITOS en 15 de Diciembre de 2014, 16:47:49
Muchas gracias migsantiago, ya estoy descargando desde el link que pusiste, ojala te funcione bien y poder ver que está pasando.
Gracias nuevamente.

saludos.
Título: Re: Iniciando pic32MZ
Publicado por: KILLERJC en 15 de Diciembre de 2014, 17:19:41
del manual de usuario de xc32
Citar
Use the __ISR(v, IPL) macro to assign the vector-number location and associate it
with the specified IPL. This will place a jump to the interrupt handler at the associated
vector location. This macro also applies the nomips16 attribute since PIC32 devices
require that interrupt handlers must use the MIPS32 instruction set

Aqui es donde esta el BOOTISA, que deberia estar en 1.
DEVCFG0/ADEVCFG0: DEVICE CONFIGURATION WORD 0

De un codigo que encontre de un arhivo llamado dma_spi.c para un PIC32MZ2048ECM144

Citar
#pragma config BOOTISA = MIPS32         // Boot ISA Selection (Boot code and Exception code is MIPS32)

Tambien veo que pones ipl3 y en el manual de xc32 hace una diferencia entre auellos que tiene registros dobles ( sombras )

Citar
The compiler also supports an IPLnAUTO IPL specifier that uses the run-time value in
SRSCTL to determine whether it should use software or SRS context-saving code. The
compiler defaults to using IPLnAUTO when the IPL specifier is omitted from the
interrupt() attribute.
For devices that do not support a shadow register set for interrupt context saving, use
IPLnSOFT for all interrupt handlers.

SRS has the shortest latency and SOFT has a longer latency due to
registers saved on the stack. AUTO adds a few cycles to test if SRS or SOFT
should be used.

Probaste si cambiando los ipl3 a ipl3soft funiona o ipl3auto ?

A ciencia cierta no se nada, estoy tirando ideas de que puede ser.

Aunque el tuyo tiene SRS para cada prioridad (tiene 7), pero si se superponen 2 con la misma prioridad habria problemas ?
Título: Re: Iniciando pic32MZ
Publicado por: migsantiago en 16 de Diciembre de 2014, 23:00:55
Kallitos, disculpa la respuesta tardía. Tengo funcionando la interrupción RX en la UART3.

+ Configuré mi PPS al pin RB3, así lo tenemos en nuestra tarjeta.

(http://www.todopic.com.ar/foros/index.php?action=dlattach;topic=43840.0;attach=23013;image)

+ Habilité una segunda instancia UART, seleccionando la UART3 porque RB3 tiene disponible URX3.

+ Habilité Harmony al principio y no moví ninguna sub-prioridad. Error. Aparentemente se deben ajustar ajustar prioridades y sub-prioridades. Puedes dejarle la misma prioridad, pero no repitas sub-prioridades entre instancias.

¿Qué pasa si no habilito bien las sub-prioridades? En mi programa se llamaba la interrupción UART2 TX... que no tiene nada que ver.  :shock:

http://ww1.microchip.com/downloads/en/DeviceDoc/61108G.pdf

Checa las diferencias que Harmony le hizo a mi código (adjuntas). :D

(http://www.todopic.com.ar/foros/index.php?action=dlattach;topic=43840.0;attach=23017;image)

¡Saludos!
Título: Re: Iniciando pic32MZ
Publicado por: doppel en 17 de Diciembre de 2014, 00:30:46
Señores Mig y Kallitos!!! uds si que la tienen clara!!! espectacular
Título: Re: Iniciando pic32MZ
Publicado por: migsantiago en 17 de Diciembre de 2014, 10:36:20
Señores Mig y Kallitos!!! uds si que la tienen clara!!! espectacular

jajaj Hola Doppel. No, no tanto jejej. Gracias. Aún necesito que Kallitos confirme lo de las sub-prioridades... sólo tuve tiempo de probar una interrupción. ¿Qué tal que se me echo a perder la del timer? No le cambié la sub-prioridad a ésa. Es cuestión de jugar con el PIC.  :mrgreen:

Y bueno, como breviario cultural... tengo la evaluación de XC32. En nivel 3 no optimiza tanto como en nivel 1. Mi código es súper sencillo por el momento. A ver si Kallitos con sus miles de líneas nos comparte su estado de optimización.
Título: Re: Iniciando pic32MZ
Publicado por: KALLITOS en 18 de Diciembre de 2014, 18:01:03
Hola migsantiago, disculpa la demora ando con contratiempos en el trabajo.

Hola hernán, un gusto leerte, y pues la llevamos de a pocos como se dice por aca.

Bueno muchachos finalmente funcionó.

Error mío, ayuda de migsantiago y al final el error es:

Me confundí con los fuses de prioridades y subprioridad. No modifiqué las que corresponden al RX sino la interrupción por FAULT.
En pocas palabras, no las configuré. Y MplabX leyó error en esa parte por eso no ejecutaba el handler.

Migsantiago, probé seteando URX1 y URX2  Prioridad y SubPrioridad con diferentes e iguales valores y en ambos casos funciona correctamente. Pero los dejaré seteados tal cual lo hace Harmony. A tener en cuenta es que las interrupciones de los 4 timer32 e intext estaban todas con Prioridad y SubPrioridad = 1  en todos.

Bueno, que alegría que ya funcionó, ya puedo continuar probando este pic. Ojalá y MPLABX me deje usar toda la memoria del micro ya que en C30 tuve que modificar el archivo p24EP512GU810.gld y poder usar toda la memoria.

Saludos.

Título: Re: Iniciando pic32MZ
Publicado por: KALLITOS en 18 de Diciembre de 2014, 21:15:50
Bueno ya lo probé y probé y ya kedó.

Muchas gracias migsantiago y KILLERJC.

Saludos
Título: Re: Iniciando pic32MZ
Publicado por: migsantiago en 19 de Diciembre de 2014, 10:24:35
Enhorabuena Kallitos.  ;-)

Para poder probar toda la ROM de tu micro te sugiero que le inyectes un arreglote basándote en un archivo de unos 1.8MB por ejemplo...

http://electrolinks.blogspot.com/2009/06/sl-file2array-v001.html

Yo una vez llené un PIC32MX (ya de los viejitos jejej) con 512kB aprox. para reproducir audio.

Saludos.