Hi guys,
I'm using Mplab for a project (with pic16f1788), where I use USART communication and I2C as well. At the time being I'm using USART to communicate with a BLE module.
I'm not getting any message from the BLE module, so I verified my USART communication. On the oscilloscope, I see the character I'm sending. I used an arduino at the same time, to use the serial monitor, and check again, but on the arduino, I'm not recieving anything.
So it seems as the Usart commmunication is not working perfectly.
I put in the the attach files, the Mplab code, arduino code, as well as a photo of the oscilloscope signal.
Does any one have an idea please ?
Thanks
I'm using Mplab for a project (with pic16f1788), where I use USART communication and I2C as well. At the time being I'm using USART to communicate with a BLE module.
I'm not getting any message from the BLE module, so I verified my USART communication. On the oscilloscope, I see the character I'm sending. I used an arduino at the same time, to use the serial monitor, and check again, but on the arduino, I'm not recieving anything.
So it seems as the Usart commmunication is not working perfectly.
I put in the the attach files, the Mplab code, arduino code, as well as a photo of the oscilloscope signal.
Does any one have an idea please ?
Thanks
C:
// ----------------Mplab Code ------------------------
#include <xc.h>
#include <stdio.h>
#include <stdlib.h>
#pragma config FOSC = INTOSC // Oscillator Selection (INTOSC oscillator: I/O function on CLKIN pin)
#pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled)
#pragma config MCLRE = ON // MCLR Pin Function Select (MCLR/VPP pin function is MCLR)
#pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled)
#pragma config CPD = OFF // Data Memory Code Protection (Data memory code protection is disabled)
#pragma config BOREN = ON // Brown-out Reset Enable (Brown-out Reset enabled)
#pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
#pragma config IESO = ON // Internal/External Switchover (Internal/External Switchover mode is enabled)
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is enabled)
// CONFIG2
#pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off)
#pragma config VCAPEN = OFF // Voltage Regulator Capacitor Enable bit (Vcap functionality is disabled on RA6.)
#pragma config PLLEN = ON // PLL Enable (4x PLL enabled)
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
#pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config LPBOR = OFF // Low Power Brown-Out Reset Enable Bit (Low power brown-out is disabled)
#pragma config LVP = ON // Low-Voltage Programming Enable (Low-voltage programming enabled)
#define _XTAL_FREQ 16000000
void init_UART()
{
TXSTA = 0x24;
RCSTA = 0x90;
SPBRG = 407; // Baud = 9600 Fosc = 16 MHz
BAUDCON = 0x08; // 16-bit Baud Rate Generator is used
APFCON1bits.TXSEL = 0;
}
void UART_Tx (char data)
{
while (TXIF == 0){}
TXREG = data;
}
char UART_Rx()
{
while (RCIF ==1){}
return RCREG;
}
void main(void)
{
TRISCbits.TRISC6 = 0; // Tx
TRISCbits.TRISC7 = 1; // Rx
int i=0;
char data = 'U'; // U - 0b01010101 just for testing
OSCCON = 0x7A; // 16 MHz
//OSCCON = 0x72; // 8 MHz
init_UART();
UART_Tx(data);
UART_Tx(data);
UART_Tx(data);
}
// ---------------- Arduino Code ------------------------
void setup()
{
Serial.begin(9600);
}
void loop()
{
char data;
while (Serial.available())
{
data = Serial.read();
Serial.println(data);
}
}
Attachments
-
411.9 KB Views: 16