PIC16F1619 curiosidad- comunicación UART

0

Estoy usando el microcontrolador PIC16F1619 dentro del panel de curiosidad, el MPLAB IDE x y el compilador XC8. Actualmente estoy intentando que mi placa lea un valor analógico y luego transmita este valor a través de una placa de arranque UART-USB ADM00559, que utiliza la placa MCP2221.

He leído la hoja de datos y he configurado todos los registros asociados que puedo ver y actualmente estoy intentando que la placa envíe simplemente cualquier valor, por ejemplo 'a' o 0x32 al registro TX1REG. Estoy usando un programa llamado 'Terminal' para ver los mensajes entrantes. He establecido la velocidad de transmisión en baudios en 9600, los bits de datos en 8, la paridad en ninguno, los bits de parada en 1, sin apretón de manos. Sin embargo, actualmente estoy obteniendo solo 0 de la comunicación sin importar el valor que asigne al TX1REG. Posibles cosas de la nota / problemas:

  1. He establecido el pin Tx en RC6, RC6PPS = 0x12, usando el código PPS relevante y deshabilité la funcionalidad de salida analógica según lo prescrito en la hoja de datos

  2. He establecido SPxBRGH, SPxBRGL en un valor de 52 según la frecuencia de reloj de 32MHz, esto se hizo con SP1BRGH = 51 y SP1BRGL = 1, ¿es correcto o necesita ser algún tipo de pareja igual?

PROGRAMA PRINCIPAL

[/ código]

/*
* File:   ledblink.c
* Author: Patrick
*
* Created on July 24, 2016, 12:09 PM
*/
#include <xc.h>                 // XC8 compiler header file
#include <stdlib.h>
#include <stdio.h>
#include "uart.h"

#define _XTAL_FREQ 32000000     // Define PIC16F1619 clock freq - 32MHz

// Above is header files - xc is for compiler, stdlib is for general  function 
//and stdio is for I/O. Below is the bit configuration

#pragma config FOSC = INTOSC    // Oscillator Selection Bits 
#pragma config PWRTE = OFF      // Power-up Timer Enable (PWRT disabled)
#pragma config MCLRE = ON       // MCLR Pin Function Select 
#pragma config CP = OFF         // Flash Program Memory Code Protection 
#pragma config BOREN = ON       // Brown-out Reset Enable 
#pragma config CLKOUTEN = OFF   // Clock Out Enable
#pragma config IESO = ON        // Internal/External Switch Over
#pragma config FCMEN = ON       // Fail-Safe Clock Monitor Enable

// CONFIG2
#pragma config WRT = OFF        // Flash Memory Self-Write Protection 
#pragma config PPS1WAY = ON     // Peripheral Pin Select one-way control
#pragma config ZCD = OFF        // Zero Cross Detect Disable Bit 
#pragma config PLLEN = ON       // PLL Enable Bit (4x PLL is always enabled)
#pragma config STVREN = ON      // Stack Overflow/Underflow Reset Enable 
#pragma config BORV = LO        // Brown-out Reset Voltage Selection 
#pragma config LPBOR = OFF      // Low-Power Brown Out Reset 
#pragma config LVP = ON         // Low-Voltage Programming Enable

// CONFIG3
#pragma config WDTCPS = WDTCPS1F// WDT Period Select (Software Control
#pragma config WDTE = OFF       // Watchdog Timer Enable (WDT disabled)
#pragma config WDTCWS = WDTCWSSW// WDT Window Select 
#pragma config WDTCCS = SWC     // WDT Input Clock Selector

int result;                     //variable to store our ADC result

int main() {  
TRISAbits.TRISA5 = 0;           // Set pin as output for LED Flash
UART_Init(9600);                // Call UART initialisation function
TRISCbits.TRISC6 = 0x00;        // Set pin RC6 as output
TRISBbits.TRISB6 = 1;
//Main while loop
while(1)
{
TX1REG = 'a';
// UART_Write(PORTBbits.RB6);
    // UART_Write('a');
        LATAbits.LATA5 = 1;      // Turn on the LED
__delay_us(10000);
        LATAbits.LATA5 = 0;      // Turn off the LED
__delay_us(10000);
return 0;
}
}          

archivo de encabezado UART

char UART_Init(const long int baudrate)
{
ANSELCbits.ANSC6 = 0;   // Disable Analog function of pin RC6/AN8
RC6PPS = 0x12;          // Sets RC6 to PPS Transmit Serial Data
SP1BRGL = 0x32;           // Initialising SPxBRGH & SPxBRGL register pair  (BAUD)
SP1BRGH = 0x1;           // Initialising SPxBRGH & SPxBRGL register pair     (BAUD)
BRGH = 0;               // Initialising BRGH and BRG16 register pair (BAUD RATE)
BRG16 = 0;              // Initialising BRGH and BRG16 register pair (BAUD RATE)
SYNC = 0;               // Clearing SYNC bit (TXxSTA reg)|Configures EUSART for asynchronous operation
SPEN = 1;               // Enables EUSART and configures TX/CK I/O pin as output
TXEN = 1;               // Enables Transmitter circuitry
}

char UART_TX_Empty()
{
return TRMT;
}

char UART_Data_Ready()
{
return RCIF;
}

char UART_Read()
{

while(!RCIF);
return RCREG;
}

void UART_Read_Text(char *Output, unsigned int length)
{
unsigned int i;
for(int i=0;i<length;i++)
Output[i] = UART_Read();
}

void UART_Write (datos de caracteres)    {    while (! TRMT);    TX1REG = datos;    }

void UART_Write_Text (char * text)    {    int i;    para (i = 0; texto [i]! = '\ 0'; i ++)    UART_Write (texto [i]);    }

    
pregunta ConfusedCheese

1 respuesta

2

Con su configuración actual, su velocidad en baudios es probablemente de 250 k, un poco más alta que sus 9600 planeadas.

Cuando BRG16 es 0, le está diciendo al PIC que solo quiere usar un divisor de velocidad de transmisión de 8 bits, por lo que el registro SPxBRGH se ignora. Así que cargue su valor calculado en SPxBRGL.

Si desea utilizar un divisor de 16 bits (y establecer BRG16 en 1), los registros SPxBRGH / SPxBRGL se emparejan y sus valores se utilizan como un valor de 16 bits con SPxBRGH contribuyendo con los 8 MSB y SPxBRGL contribuyendo los 8 LSBs.

    
respondido por el brhans

Lea otras preguntas en las etiquetas