axelkol
Newbie
I am trying to program my MCU such that it transmits a message through an xbee module connected to the MCU and the message is received to the XCTU command console. I do not see any message in the XCTU console. I have written the code and properly configured both the xbee modules(I think). The code is following:
Am I missing any step in configuring anything or is my code wrong? I want to know why the xbee module connected to the laptop doesn't show any message in the XCTU console command.
C:
#include<libpic30.h>
#include<stdio.h>
#include<string.h>
#include <p33FJ128MC804.h>
//#include<UART.h>
// DSPIC33FJ128MC804 Configuration Bit Settings
// 'C' source line config statements
// FBS
#pragma config BWRP = WRPROTECT_OFF // Boot Segment Write Protect (Boot Segment may be written)
#pragma config BSS = NO_FLASH // Boot Segment Program Flash Code Protection (No Boot program Flash segment)
#pragma config RBS = NO_RAM // Boot Segment RAM Protection (No Boot RAM)
// FSS
#pragma config SWRP = WRPROTECT_OFF // Secure Segment Program Write Protect (Secure segment may be written)
#pragma config SSS = NO_FLASH // Secure Segment Program Flash Code Protection (No Secure Segment)
#pragma config RSS = NO_RAM // Secure Segment Data RAM Protection (No Secure RAM)
// FGS
#pragma config GWRP = OFF // General Code Segment Write Protect (User program memory is not write-protected)
#pragma config GSS = OFF // General Segment Code Protection (User program memory is not code-protected)
// FOSCSEL
#pragma config FNOSC = PRI // Oscillator Mode (Primary Oscillator (XT, HS, EC))
#pragma config IESO = ON // Internal External Switch Over Mode (Start-up device with FRC, then automatically switch to user-selected oscillator source when ready)
// FOSC
#pragma config POSCMD = XT // Primary Oscillator Source (XT Oscillator Mode)
#pragma config OSCIOFNC = OFF // OSC2 Pin Function (OSC2 pin has clock out function)
#pragma config IOL1WAY = ON // Peripheral Pin Select Configuration (Allow Only One Re-configuration)
#pragma config FCKSM = CSDCMD // Clock Switching and Monitor (Both Clock Switching and Fail-Safe Clock Monitor are disabled)
// FWDT
#pragma config WDTPOST = PS32768 // Watchdog Timer Postscaler (1:32,768)
#pragma config WDTPRE = PR128 // WDT Prescaler (1:128)
#pragma config WINDIS = OFF // Watchdog Timer Window (Watchdog Timer in Non-Window mode)
#pragma config FWDTEN = ON // Watchdog Timer Enable (Watchdog timer always enabled)
// FPOR
#pragma config FPWRT = PWR128 // POR Timer Value (128ms)
#pragma config ALTI2C = OFF // Alternate I2C pins (I2C mapped to SDA1/SCL1 pins)
#pragma config LPOL = ON // Motor Control PWM Low Side Polarity bit (PWM module low side output pins have active-high output polarity)
#pragma config HPOL = ON // Motor Control PWM High Side Polarity bit (PWM module high side output pins have active-high output polarity)
#pragma config PWMPIN = ON // Motor Control PWM Module Pin Mode bit (PWM module pins controlled by PORT register at device Reset)
// FICD
#pragma config ICS = PGD1 // Comm Channel Select (Communicate on PGC1/EMUC1 and PGD1/EMUD1)
#pragma config JTAGEN = OFF // JTAG Port Enable (JTAG is Disabled)
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
#define BRGVAL ((FCY/BAUDRATE)/16)-1
#define DELAY_105uS asm volatile ("REPEAT, #4201"); Nop(); // 105uS delay
//#include <uart.h>
#include <xc.h>
char uart1_buffer[100];
int uart_index = 0;
int i;
int main(void)
{
__builtin_write_OSCCONL(OSCCON & 0xbf);
// RPOR10bits.RP20R = 3; // UART1 TX @ RP20(RC4)
__builtin_write_OSCCONL(OSCCON | 0x40);
// __delay32(1000000)
// TRISCbits.TRISC4 = 0; // UART1 TX, RP20 is device RC4
initU1();
// UART1Init();
// UART1TransmitString("aaAa\r\n");
char message[5] = {'a', 'a', 'A', 'a', 'A'};
// __delay_ms(500);
while(1)
{
}
return 0;
}
void initU1(void)
{
U1MODEbits.STSEL = 0;
U1MODEbits.PDSEL = 0;
U1MODEbits.ABAUD = 0;
U1MODEbits.BRGH = 0;
U1BRG = BRGVAL;
U1STAbits.UTXISEL0 = 0;
U1STAbits.UTXISEL1 = 0;
IEC0bits.U1TXIE = 1;
U1MODEbits.UARTEN = 1;
U1STAbits.UTXEN = 1;
DELAY_105uS
U1TXREG = 'a';
}
void __attribute__((__interrupt__))_U1TXInterrupt(void)
{
IFS0bits.U1TXIF = 0;
U1TXREG = 'a';
}