jueves, 23 de febrero de 2017

PRACTICA # 4 LCD GRAFICA 96x64 (SPI)

OBJETIVO:
       Se creará el driver para la lcd grafica 96x64 con interfaz de comunicación RSPI. Se mostrará un mensaje de 7 líneas.
  • Crear y configurar la unidad RSPI0
  • Inicializar los pines de LCD-CS y LCD-RS
  • Incluimos todos los archivos de la librería gráfica en una carpeta

DESARROLLO:
  •  Del manual Renesas RX63N RDK User's Manual ubicamos los pines del LCD: 

  • Del YRDKRX63N schematic ubicamos el LCD okaya:

PASOS:
  • Creación de un proyecto:
1.- Abrir el software e2studio
2.- New/ C Project / Renesas RXC ToolChain


3.- Seleccionar el target R5F563NB, debug hardware Segger jLink, después next


4.- Seleccionar la librería math.c para las funciones test de la LCD gráfica.


5.- Seleccionar C/C++ Source file y por ultimo Finish.


6.- Configuraremos el SPI por medio del módulo RSPI0 a 0.5 Mbps en el archivo r_cg_serial_SPI.c:

void R_RSPI0_Create(void)
{
            //SYSTEM.PRCR.WORD = 0xA502; /* Protect off */
            MSTP(RSPI0) = 0; //Enable SPI0
            //SYSTEM.PRCR.WORD = 0xA500; /* Protect on  */

            MPC.PC5PFS.BYTE = 0x0D; /* PC5 is RSPCKA */
            MPC.PC6PFS.BYTE = 0x0D; /* PC6 is MOSIA */
            MPC.PC7PFS.BYTE = 0x0D; /* PC7 is MISOA */

            //PORT C DDR
            PORTC.PDR.BIT.B5 = 1; //An output pin    RSPCK output
            PORTC.PDR.BIT.B6 = 1; //An output pin    MOSI output
            PORTC.PDR.BIT.B7 = 0; //An input pin     MISO = input
            PORTC.PMR.BIT.B5 = 1; // como periferico
            PORTC.PMR.BIT.B6 = 1; // como periferico
            PORTC.PMR.BIT.B7 = 1; // como periferico

            // inicializa pines
            PORTC.PDR.BIT.B2 = 1; // como salida LCD-CS
            PORT5.PDR.BIT.B1 = 1; // como salida LCD-RS
            PORTC.PDR.BIT.B3 = 1; // como salida reset
            PORTC.PMR.BIT.B2 = 0; // como I/O general
            PORT5.PMR.BIT.B1 = 0; // como I/O general
            PORTC.PMR.BIT.B3 = 0; // como I/O general
            PORTC.PODR.BIT.B3 = 0; // Pull RSTOUT# inverting buffer low so RSTOUT# goes high, releasing reset state.

            //SPPCR register
            RSPI0.SPPCR.BIT.SPLP = 0; //Disable loopback mode
            RSPI0.SPPCR.BIT.SPLP2 = 0; //Disable loopback mode
            //RSPI0.SPPCR.BIT.SPOM = 0; //CMOS output
            RSPI0.SPPCR.BIT.MOIFV = 0; //MOSI idle fixed value equal 0
            RSPI0.SPPCR.BIT.MOIFE = 0; //MOSI output value equal final data from previous transfer

            /* Set RSPI bit rate (SPBR) */
            /* -Set baud rate to   0.5 Mbps = 48MHz / (2 * (47 + 1) * 2^0) */
            RSPI0.SPBR = 47;

            //SPDCR register
            RSPI0.SPDCR.BIT.SPFC = 0; //Number of frames
            //RSPI0.SPDCR.BIT.SLSEL = 0; //SSL0 to SSL3 as output
            RSPI0.SPDCR.BIT.SPRDTD = 0; //SPDR values are read from the receive buffer
            RSPI0.SPDCR.BIT.SPLW = 0; //SPDR is accessed in words

            //SPCKD register
            RSPI0.SPCKD.BIT.SCKDL = 0; //1 RSPCK delay for clock

            //SSLND register
            RSPI0.SSLND.BIT.SLNDL = 0; //1 RSPCK delay for slave select negation

            //SPND register
            RSPI0.SPND.BIT.SPNDL = 0; //1 RSPCK + 2 PCLK delay for next-access

            //SPCR2 register
            RSPI0.SPCR2.BIT.SPPE = 0; //Parity disable
            RSPI0.SPCR2.BIT.SPOE = 0; //Parity mode
            RSPI0.SPCR2.BIT.SPIIE = 0; //Disable idle interrupt
            RSPI0.SPCR2.BIT.PTE = 0; //Disable the self-diagnostics of the parity circuit

            //SPCMOD0 register (Graphic display)
            RSPI0.SPCMD0.BIT.CPHA = 0; //Data sampling on odd edge, data variation on even edge
            RSPI0.SPCMD0.BIT.CPOL = 0; //RSPCK = 0 when idle
            RSPI0.SPCMD0.BIT.BRDV = 0; //Bit Rate = 3MHz (according with SPBR register)
            RSPI0.SPCMD0.BIT.SSLA = 0; //SSL3-A for graphic display
            RSPI0.SPCMD0.BIT.SSLKP = 0; //Negative all SSL signals upon completion of transfer
            RSPI0.SPCMD0.BIT.SPB = 7; //Data length = 8bits
            RSPI0.SPCMD0.BIT.LSBF = 0; //MSB first
            RSPI0.SPCMD0.BIT.SPNDEN = 0; //Disable next-access delay
            RSPI0.SPCMD0.BIT.SLNDEN = 0; //Disable SSL negation delay
            RSPI0.SPCMD0.BIT.SCKDEN = 0; //An RSPCK delay of 1 RSPCK

            //SPCR register
            RSPI0.SPCR.BIT.SPMS = 1; //SPI operation (four-wire)
            RSPI0.SPCR.BIT.TXMD = 0; //Full-duplex operation
            RSPI0.SPCR.BIT.MODFEN = 0; //Disable detection of mode fault error
            RSPI0.SPCR.BIT.MSTR = 1; //Master mode
            RSPI0.SPCR.BIT.SPEIE = 0; //Disable error interrupt requests
            RSPI0.SPCR.BIT.SPTIE = 1; //enable transmit interrupt requests
            RSPI0.SPCR.BIT.SPRIE = 1; //enable receive interrupt requests
            RSPI0.SPCR.BIT.SPE = 1; //Enable RSPI function

            //SSLP register
            RSPI0.SSLP.BIT.SSL0P = 1; //SSL0 signal is 1 active
            RSPI0.SSLP.BIT.SSL1P = 1; //SSL1 signal is 1 active
            RSPI0.SSLP.BIT.SSL2P = 1; //SSL2 signal is 1 active
            RSPI0.SSLP.BIT.SSL3P = 1; //SSL3 signal is 1 active

            //SPSCR register
            RSPI0.SPSCR.BIT.SPSLN = 0; //RSPI sequence
}

7.- Inicializamos la LCD con la función en main.c  

void SR_LCD_GRAPH(void)
{
            LCDInit();
            LCDClear();
            //LCDTest2();
            LCDFont(FONT_LARGE);
}

8.- La función de envió se muestra a continuación y está en el archivo r_cg_serial_SPI.c

MD_STATUS R_RSPI0_Send_Receive(uint8_t *  tx_buf, uint16_t tx_num, uint8_t *  rx_buf)
{
    MD_STATUS status = MD_OK;

            RSPI0.SPDR.WORD.H =  0x00ff & *tx_buf;
            //Wait for transfer complete
            while (RSPI0.SPSR.BIT.IDLNF)
            {
                        __nop();
            }
            (void) RSPI0.SPDR.WORD.H ;
            G_SPI_SendingData = 0;
    return (status);

}


9.- El API de usuario RDKRX63N_spi, YRDKRX63N_LCD y el driver ST7579_LCD, glyph_api se encuentran en la carpeta Glyph:


  • Agregar código, compilar y debug:
1.- Bajar el código de:
--.> Practica #4

2.- Compilar con el icono del martillo y debug con el icono del insecto:


DEMOSTRACIÓN:


miércoles, 22 de febrero de 2017

PRACTICA # 5 CONVERTIDOR A/D 10 BITS

OBJETIVO:
       Se hará uso del módulo A/D de 10 bits de resolución con el que cuenta el MCU R5F563NB de la tarjeta de evaluación YRDKRX63N. El valor de muestreo será visualizado el LCD 96x64 en tiempo real.
  • Configurar el modulo A/D de 10 bits
  • Imprimir el valor del convertidor en el LCD.
DESARROLLO:
  •  Del manual Renesas RX63N RDK User's Manual ubicamos el canal AN2
     
  •  Debido a que no se tiene un potenciómetro conectado a un canal A/D 10 bits utilizaremos el conector PMOD1 en su entrada Nº1 PE4. 

  •  Del RX63N Group User's Manual: Hardware página 1748 hacemos referencia al canal analógico 2 cuyo registro de lectura es ADDRC:

PASOS:
  •  Creación de un proyecto:
1.- Abrir el software e2studio
2.- New/ C Project / Renesas RXC ToolChain


3.- Seleccionar el target R5F563NB, debug hardware Segger jLink, después next


4.- Seleccionar C/C++ Source file y por ultimo Finish.


5.- Configuraremos el A/D a 10 bits de resolución y un tiempo de muestreo de 2.0 us en el archivo r_cg_adc.c
void R_ADC_Create(void)
{   
            MSTP(AD) = 0; // AD 10 bits   enable

            /* set direction and enable input */
            PORTE.PDR.BIT.B4 = 0;               // PE4 como input
            PORTE.PMR.BIT.B4 = 0;               // como I/O
           MPC.PE4PFS.BYTE = 0x80;   // Set port function register to analog input, no interrupt.

            AD.ADCSR.BYTE = 0x00;
            //AD.ADCSR.BIT.ADIE =0;   // ADI interrupt is disabled
            //AD.ADCSR.BIT.ADST = 0;  //Stops A/D conversion

            /* software trigger, single scan mode, PCLK/8 = ADCLK = 6 MHz */
            AD.ADCR.BYTE = 0x00;

            /* flush LSB end */
            AD.ADCR2.BYTE = 0x00;
            //AD.ADCR2.BIT.DPSEL = 0;

            //Self-Diagnostic
            AD.ADDIAGR.BYTE = 0x0;

            /* sampling state register. adds to conversion time such that
            //Sampling time (μs) = Setting value of ADSSTR / ADCLK (MHz)            ADCLK = PCLK / 8 = 6 Mhz
            //
             Ts = 2 uS, Fs = 500 kHz */
            AD.ADSSTR = 12;
}

6.- La función main queda como sigue:

void main(void)
{
            set_ipl(0);              // enable interrupts
            SR_Oscilador();          //  F = 96 Mhz
            SR_LCD_GRAPH();          //  LCD 96x64
            SR_TIMER_0();            // Inicializa el Timer 0 en cascada para 16 bits
            SR_ADC();                // ADC 10 bits ch 2 PE4


            while(1)
            {
                        AdcValue = adc_get_vdd();          // adquiere el valor 10 bits del ch 2 PE4
                        voltage = (3.3 * AdcValue) / 1024.0;
                        LCDPrintf(0, 0, "Microcarsil ");
                        LCDPrintf(1, 0, "    2017    ");
                        LCDPrintf(2, 0, "Carlos Silva");
                        LCDPrintf(3, 0, "            ");
                        LCDPrintf(4, 0, "Practica #5 ");
                        LCDPrintf(5, 0, "            ");
                        LCDPrintf(6, 0, "AD10 = %.3f ", voltage);
                        LCDPrintf(7, 0, "            ");
                        delay_ms(100);
            }

}

  • Agregar código, compilar y debug:
1.- Bajar el código de:
--> Practica #5

2.- Compilar con el icono del martillo y debug con el icono del insecto:


VÍDEO: