pic32mz EF UART - frequency

Can anyone give me the configuration and code for sending a character in UART?
I am using Pic32mz EF starter kit and MPLAB X-IDE v5.15.
I tried a code but it is not giving out any UART in tera term or putty.
// PIC32MZ2048EFM144 Configuration Bit Settings
// 'C' source line config statements
// DEVCFG3
#pragma config USERID = 0xFFFF // Enter Hexadecimal value (Enter Hexadecimal value)
#pragma config FMIIEN = OFF // Ethernet RMII/MII Enable (RMII Enabled)
#pragma config FETHIO = OFF // Ethernet I/O Pin Select (Alternate Ethernet I/O)
#pragma config PGL1WAY = OFF // Permission Group Lock One Way Configuration (Allow multiple reconfigurations)
#pragma config PMDL1WAY = OFF // Peripheral Module Disable Configuration (Allow multiple reconfigurations)
#pragma config IOL1WAY = OFF // Peripheral Pin Select Configuration (Allow multiple reconfigurations)
#pragma config FUSBIDIO = OFF // USB USBID Selection (Controlled by Port Function)
// DEVCFG2
#pragma config FPLLIDIV = DIV_3 // System PLL Input Divider (3x Divider)
#pragma config FPLLRNG = RANGE_5_10_MHZ // System PLL Input Range (5-10 MHz Input)
#pragma config FPLLICLK = PLL_POSC // System PLL Input Clock Selection (POSC is input to the System PLL)
#pragma config FPLLMULT = MUL_100 // System PLL Multiplier (PLL Multiply by 100)
#pragma config FPLLODIV = DIV_2 // System PLL Output Clock Divider (2x Divider)
#pragma config UPLLFSEL = FREQ_12MHZ // USB PLL Input Frequency Selection (USB PLL input is 12 MHz)
// DEVCFG1
#pragma config FNOSC = SPLL // Oscillator Selection Bits (System PLL)
#pragma config DMTINTV = WIN_127_128 // DMT Count Window Interval (Window/Interval value is 127/128 counter value)
#pragma config FSOSCEN = OFF // Secondary Oscillator Enable (Disable SOSC)
#pragma config IESO = OFF // Internal/External Switch Over (Disabled)
#pragma config POSCMOD = OFF // Primary Oscillator Configuration (Primary osc disabled)
#pragma config OSCIOFNC = OFF // CLKO Output Signal Active on the OSCO Pin (Disabled)
#pragma config FCKSM = CSDCMD // Clock Switching and Monitor Selection (Clock Switch Disabled, FSCM Disabled)
#pragma config WDTPS = PS1048576 // Watchdog Timer Postscaler (1:1048576)
#pragma config WDTSPGM = STOP // Watchdog Timer Stop During Flash Programming (WDT stops during Flash programming)
#pragma config WINDIS = NORMAL // Watchdog Timer Window Mode (Watchdog Timer is in non-Window mode)
#pragma config FWDTEN = OFF // Watchdog Timer Enable (WDT Disabled)
#pragma config FWDTWINSZ = WINSZ_25 // Watchdog Timer Window Size (Window size is 25%)
#pragma config DMTCNT = DMT31 // Deadman Timer Count Selection (2^31 (2147483648))
#pragma config FDMTEN = OFF // Deadman Timer Enable (Deadman Timer is disabled)
// DEVCFG0
#pragma config DEBUG = OFF // Background Debugger Enable (Debugger is disabled)
#pragma config JTAGEN = OFF // JTAG Enable (JTAG Disabled)
#pragma config ICESEL = ICS_PGx2 // ICE/ICD Comm Channel Select (Communicate on PGEC2/PGED2)
#pragma config TRCEN = OFF // Trace Enable (Trace features in the CPU are disabled)
#pragma config BOOTISA = MIPS32 // Boot ISA Selection (Boot code and Exception code is MIPS32)
#pragma config FECCCON = OFF_UNLOCKED // Dynamic Flash ECC Configuration (ECC and Dynamic ECC are disabled (ECCCON bits are writable))
#pragma config FSLEEP = OFF // Flash Sleep Mode (Flash is powered down when the device is in Sleep mode)
#pragma config DBGPER = PG_ALL // Debug Mode CPU Access Permission (Allow CPU access to all permission regions)
#pragma config SMCLR = MCLR_NORM // Soft Master Clear Enable bit (MCLR pin generates a normal system Reset)
#pragma config SOSCGAIN = GAIN_2X // Secondary Oscillator Gain Control bits (2x gain setting)
#pragma config SOSCBOOST = ON // Secondary Oscillator Boost Kick Start Enable bit (Boost the kick start of the oscillator)
#pragma config POSCGAIN = GAIN_2X // Primary Oscillator Gain Control bits (2x gain setting)
#pragma config POSCBOOST = ON // Primary Oscillator Boost Kick Start Enable bit (Boost the kick start of the oscillator)
#pragma config EJTAGBEN = NORMAL // EJTAG Boot (Normal EJTAG functionality)
// DEVCP0
#pragma config CP = OFF // Code Protect (Protection Disabled)
// SEQ3
#pragma config TSEQ = 0xFFFF
#pragma config CSEQ = 0xFFFF
// DEVADC0
#pragma config ADCFG = 0xFFFFFFFF
#include <xc.h>
#include <proc/p32mz2048efm144.h>
void main()
{
U2MODEbits.STSEL = 0;
U2MODEbits.PDSEL = 0b00;
IEC4bits.U2TXIE = 1;
IPC36bits.U2TXIP = 0b111;
IPC36bits.U2TXIS = 0b11;
U2STAbits.UTXISEL = 0b10;
U2STAbits.UTXEN = 1;
U2MODEbits.UEN = 0b00;
U2MODEbits.ON = 1;
U2MODEbits.BRGH = 0;
U2BRG = 129;
int i;
for(i=0;i<100;i++)
{
U2STAbits.UTXEN = 1; // Make sure transmitter is enabled
while(U2STAbits.UTXBF); // Wait while buffer is full
U2TXREG =(char) i;
}
}
I think there is a problem with my configuration bits and Baud rate. Can you please help me in setting the correct baud rate and configuration bits?
Thanks & Regards,
Vibhu.

I'm having a problem with a project of mine that I haven't figured out yet (I get garbled data), but here's what I do see in yours. You will need to set the TRISx bits for the TX and RX pins to OUT and IN, plus you'll need to map those UART functions to the physical pins through U2RXR and RPDx registers. You also need to clear the bits for those two pins to digital in the appropriate ANSELx register(s).

You can calculate the baud rate by using this formula:
U2BRG = (unsigned short int)(((float)PERIPHERAL_CLOCK / ((float)BAUD_RATE * (float)BAUD_CLOCK)) - (float)0.5);
If U2MODEbits.BRGH is set to High Baud Rate, then your BAUD_CLOCK should be 4, otherwise 16.
And for writing a char by polling the TRMT flag:
while(!U2STAbits.TRMT) {}
U2TXREG = (char) i;
You should set the following bit only once, as this is an initialization process, no need to do it every time you're about to send a char.
U2STAbits.UTXEN = 1; // Make sure transmitter is enabled
And you also don't have a main while() loop, and your program is probably crashing every time the cpu finishes with executing the for loop.

Related

TM4321GH6PM - why is GPIODATA register initializing itself and how to read and write to it properly?

Context: I am following a Embedded Systems course that uses the TM4C321GHP6M microcontroller. The IDE being used is the uvision ide by keil. The purpose of the program I am running is to turn on an on-board LED using PF2 and when Switch 1, connected via PF4, is pressed the led will blink. Once switch 1 is released it LED will go back to just being ON.
// BranchingFunctionsDelays.c Lab 6
// Runs on LM4F120/TM4C123
// Use simple programming structures in C to
// toggle an LED while a button is pressed and
// turn the LED on when the button is released.
// This lab will use the hardware already built into the LaunchPad.
// Daniel Valvano, Jonathan Valvano
// January 15, 2016
// built-in connection: PF0 connected to negative logic momentary switch, SW2
// built-in connection: PF1 connected to red LED
// built-in connection: PF2 connected to blue LED
// built-in connection: PF3 connected to green LED
// built-in connection: PF4 connected to negative logic momentary switch, SW1
#include "TExaS.h"
#define GPIO_PORTF_DATA_R (*((volatile unsigned long *)0x400253FC))
#define GPIO_PORTF_DIR_R (*((volatile unsigned long *)0x40025400))
#define GPIO_PORTF_AFSEL_R (*((volatile unsigned long *)0x40025420))
#define GPIO_PORTF_PUR_R (*((volatile unsigned long *)0x40025510))
#define GPIO_PORTF_DEN_R (*((volatile unsigned long *)0x4002551C))
#define GPIO_PORTF_AMSEL_R (*((volatile unsigned long *)0x40025528))
#define GPIO_PORTF_PCTL_R (*((volatile unsigned long *)0x4002552C))
#define SYSCTL_RCGC2_R (*((volatile unsigned long *)0x400FE108))
#define SYSCTL_RCGC2_GPIOF 0x00000020 // port F Clock Gating Control
// basic functions defined at end of startup.s
void DisableInterrupts(void); // Disable interrupts
void EnableInterrupts(void); // Enable interrupts
void Delay100ms(unsigned long time);
void init(void);
int main(void){
TExaS_Init(SW_PIN_PF4, LED_PIN_PF2); // activate grader and set system clock to 80 MHz
init();// initialization goes here
EnableInterrupts(); // enable interrupts for the grader
while(1){
unsigned long in;
Delay100ms(1);
in = GPIO_PORTF_DATA_R & 0x10; //read switch
if(in == 0x00){//if PF4 == 0 (switch is pressed)
GPIO_PORTF_DATA_R ^= 0x04; //toggle PF2
}
else{//if PF4 == 1 (switch not pressed)
GPIO_PORTF_DATA_R = 0x04; //set PF2 so LED is ON
}
}
}
void init(void){
SYSCTL_RCGC2_R = SYSCTL_RCGC2_GPIOF; //turn on clock for Port F
Delay100ms(1);
GPIO_PORTF_AMSEL_R = 0x00; //clear PF4 and PF2 bits in port F AMSEL to disable analog
GPIO_PORTF_PCTL_R = 0x00; //clear PF4 and PF2 bit fields in Portf PCTL to config as GPIO
GPIO_PORTF_DIR_R = 0x04; //Set port F dir reg so PF4 is in and PF2 is out
GPIO_PORTF_AFSEL_R = 0x00; //clear PF4 and PF2 bits in port F AFSEL to disable alt func
GPIO_PORTF_DEN_R = 0x14; //set PF4 and PF2 bits in Port F DEN to enable digital
GPIO_PORTF_PUR_R = 0x10; //set PF4 bit in Port F PUR to activate internal pullup
GPIO_PORTF_DATA_R = 0x04; //set PF2 bit in Port F DATA so the LED is init on
PF2 = 0x20;
}
void Delay100ms(unsigned long time){
unsigned long i = 1333333;
while(time > 0){
while(i > 0){
i--;
}
time--;
}
}
For some reason once the program goes to the init() function and steps over SYSCTL_RCGC2_R = SYSCTL_RCGC2_GPIOF; and then Delay100ms(1); the register GPIO_PORTF_DATA_R is initialized with value 0x011. I am not sure what is causing this. Additionally when I attempt to set GPIO_PORTF_DATA_R = 0x04 it then holds the value 0x15? This behavior is very strange and after reading through the data sheet I can see that GPIODATA is read and written to in a unconventional way. For reference please see pages 662 and 654. Would anyone be able to explain this behavior and how I could properly read and write to this register?
This line:
SYSCTL_RCGC2_R = SYSCTL_RCGC2_GPIOF; //turn on clock for Port F
enables the GPIOF clock. When the clock for a peripheral is not running its registers cannot be read or written. So in the debugger you do not see the register value until after the clock is enabled.
Although the reset state of GPIODATA is documented as 0x00000000, that is only true for output the default state of GPIODIR sets every GPIO pin to an input. So 0x11 simply reflects the input state of that port, and PF0 and PF4 happen to be in the logic-high state.
You would need to consult the board schematic to determine what is connected to those pins and why they might be in the high state, but you have already mentioned that PF4 is connected to SW1, and the code sets that pin as an input with internal pull-up. I am guessing that this is a Tiva LaunchPad board having:
Pressing the SW1 push-button will pull the pin low, and the PF4 pit will become zero. The internal pull-up resistor is enabled by default for PF4, so it is not floating even though you have not yet configured it at that point. PF0 GPIOPUR default is floating (per table 10-8), so unless it is configured explicitly to pull-up, its state is indeterminate when connected as on the LaunchPad to SW2.
With respect to perceived "unconventional" behaviour, all peripheral registers on any MCU behave as defined by their manufacturer documentation according to the hardware design. Hardware registers are not RAM (even when memory-mapped) and need not behave like RAM. In particular, unlike RAM, they may have deterministic reset state, and be either read-write, read-only, or write-only. Writing a bit need not modify that bit, registers may change value independently of reads or writes by code.

PIC16F18876 uart config failing

I am using PIC16F18875 and XC8 compiler. I am using PPS for the first time. I have configure the UART but it is not working propely. Frequency is 8MHz.
i have set input PPS and Output PPS mode.
// CONFIG1
#pragma config FEXTOSC = OFF // External Oscillator mode selection bits (Oscillator not enabled)
#pragma config RSTOSC = HFINT1 // Power-up default value for COSC bits (HFINTOSC (1MHz))
#pragma config CLKOUTEN = OFF // Clock Out Enable bit (CLKOUT function is disabled; i/o or oscillator function on OSC2)
#pragma config CSWEN = ON // Clock Switch Enable bit (Writing to NOSC and NDIV is allowed)
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable bit (FSCM timer disabled)
// CONFIG2
#pragma config MCLRE = ON // Master Clear Enable bit (MCLR pin is Master Clear function)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config LPBOREN = OFF // Low-Power BOR enable bit (ULPBOR disabled)
#pragma config BOREN = OFF // Brown-out reset enable bits (Brown-out reset disabled)
#pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (VBOR) set to 1.9V on LF, and 2.45V on F Devices)
#pragma config ZCD = OFF // Zero-cross detect disable (Zero-cross detect circuit is disabled at POR.)
#pragma config PPS1WAY = OFF // Peripheral Pin Select one-way control (The PPSLOCK bit can be cleared and set only once in software)
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable bit (Stack Overflow or Underflow will cause a reset)
// CONFIG3
#pragma config WDTCPS = WDTCPS_31// WDT Period Select bits (Divider ratio 1:65536; software control of WDTPS)
#pragma config WDTE = OFF // WDT operating mode (WDT Disabled, SWDTEN is ignored)
#pragma config WDTCWS = WDTCWS_7// WDT Window Select bits (window always open (100%); software control; keyed access not required)
#pragma config WDTCCS = SC // WDT input clock selector (Software Control)
// CONFIG4
#pragma config WRT = OFF // UserNVM self-write protection bits (Write protection off)
#pragma config SCANE = available// Scanner Enable bit (Scanner module is available for use)
#pragma config LVP = OFF // Low Voltage Programming Enable bit (Low Voltage programming enabled. MCLR/Vpp pin function is MCLR.)
// CONFIG5
#pragma config CP = OFF // UserNVM Program memory code protection bit (Program Memory code protection disabled)
#pragma config CPD = OFF // DataNVM code protection bit (Data EEPROM code protection disabled)
#include <xc.h>
#include <stdint.h>
void InitUART1(void)
{
TRISCbits.TRISC6 = 0;
TRISCbits.TRISC7 = 1;
RXPPS = 0x17;
TXPPS = 0x10;
TX1STA = 0X00;
RC1STA = 0x90;
BAUD1CON = 0X08;
// SP1BRGL = 26;
// SP1BRGH = 0x00;
SPBRG = 25;
TX1STA |= 0X20;
}
void send_char_uart1(uint8_t c)
{
TX1REG = c;
while(PIR3bits.TXIF == 0);
}
void send_string_uart1(uint8_t *str)
{
while(*str != '\0')
{
send_char_uart1(*str++);
}
}
void main(void) {
OSCCON1 = 0x60; //
OSCFRQ = 0x03; //8 MHZ
ANSELC = 0X00;
InitUART1();
while(1)
{
send_char_uart1('s');
}
return;
}
I have set the Input Pins and also tried to keep the minimal functionality.
Here, I am using UART in polling method only.
In your configuration is TX pin RC6 so switch:
TXPPS = 0x16;
0x10 is incorrect value
Problem is solved. Above mentioned code is working.Problem was with hardware. Pin was not soldered properly.

CDC USB on dspic33EP

I'm trying to get my pic to communicate via USB with my PC (MacBook Pro).
Here is the schematic for my homemade board, using a dsPIC33EP256MU806:
I've adapted microchip's MLA Library, specifically, the cdc_basic firmware.
Following are the changes I made to the code:
Changed ACLKCON3 to 0x24C3, since I'm using a 16MHz crystal oscillator.
Removed all the code relative to buttons and leds.
The code wasn't compiling, so I had to add some #includes.
Here are my pragma configurations:
// FGS
#pragma config GWRP = OFF // General Segment Write-Protect bit (General Segment may be written)
#pragma config GSS = OFF // General Segment Code-Protect bit (General Segment Code protect is disabled)
#pragma config GSSK = OFF // General Segment Key bits (General Segment Write Protection and Code Protection is Disabled)
// FOSCSEL
#pragma config FNOSC = FRC // Initial Oscillator Source Selection bits (Internal Fast RC (FRC))
#pragma config IESO = OFF // Two-speed Oscillator Start-up Enable bit (Start up with user-selected oscillator source)
// FOSC
#pragma config POSCMD = HS // Primary Oscillator Mode Select bits (XT Crystal Oscillator Mode)
#pragma config OSCIOFNC = OFF // OSC2 Pin Function bit (OSC2 is clock output)
#pragma config IOL1WAY = OFF // Peripheral pin select configuration (Allow multiple reconfigurations)
#pragma config FCKSM = CSECMD // Clock Switching Mode bits (Clock switching is enabled,Fail-safe Clock Monitor is disabled)
// FWDT
#pragma config WDTPOST = PS32768 // Watchdog Timer Postscaler bits (1:32,768)
#pragma config WDTPRE = PR128 // Watchdog Timer Prescaler bit (1:128)
#pragma config PLLKEN = ON // PLL Lock Wait Enable bit (Clock switch to PLL source will wait until the PLL lock signal is valid.)
#pragma config WINDIS = OFF // Watchdog Timer Window Enable bit (Watchdog Timer in Non-Window mode)
#pragma config FWDTEN = ON // Watchdog Timer Enable bit (Watchdog timer always enabled)
// FPOR
#pragma config FPWRT = PWR128 // Power-on Reset Timer Value Select bits (128ms)
#pragma config BOREN = ON // Brown-out Reset (BOR) Detection Enable bit (BOR is enabled)
#pragma config ALTI2C1 = OFF // Alternate I2C pins for I2C1 (SDA1/SCK1 pins are selected as the I/O pins for I2C1)
// FICD
#pragma config ICS = NONE // ICD Communication Channel Select bits (Reserved, do not use)
#pragma config RSTPRI = PF // Reset Target Vector Select bit (Device will obtain reset instruction from Primary flash)
#pragma config JTAGEN = OFF // JTAG Enable bit (JTAG is disabled)
// FAS
#pragma config AWRP = OFF // Auxiliary Segment Write-protect bit (Aux Flash may be written)
#pragma config APL = OFF // Auxiliary Segment Code-protect bit (Aux Flash Code protect is disabled)
#pragma config APLK = OFF // Auxiliary Segment Key bits (Aux Flash Write Protection and Code Protection is Disabled)
Here is my main loop:
int main(void)
{
SYSTEM_Initialize(SYSTEM_STATE_USB_START);
USBDeviceInit();
USBDeviceAttach();
LATEbits.LATE5=1;
while(1)
{
SYSTEM_Tasks();
#if defined(USB_POLLING)
// Interrupt or polling method. If using polling, must call
// this function periodically. This function will take care
// of processing and responding to SETUP transactions
// (such as during the enumeration process when you first
// plug in). USB hosts require that USB devices should accept
// and process SETUP packets in a timely fashion. Therefore,
// when using polling, this function should be called
// regularly (such as once every 1.8ms or faster** [see
// inline code comments in usb_device.c for explanation when
// "or faster" applies]) In most cases, the USBDeviceTasks()
// function does not take very long to execute (ex: <100
// instruction cycles) before it returns.
USBDeviceTasks();
#endif
//Application specific tasks
APP_DeviceCDCBasicDemoTasks();
}//end while
}//end main
The rest of the code is here: https://github.com/RuiLoureiro/CDC_USB_dsPIC33e256MU806
When I list the USB devices currently connected to my macbook, using ls /dev/tty.*, the pic is not showing up.
Any help will be greatly appreciated.

SPI slaveon DSPIC

Working on DSPIC33FJ128MC804
The problem :
I am completely unable to configura the SPI as slave. SPI Interrupt does never fire. if(SPI2STATbits.SPIRBF || SPI2STATbits.SPIROV) is always evaluated as false too.
I tried
with SSEN enabled and disabled, and many other configurations...
The clock is present and generated by an Arduino Uno as master, the pin mapping has been checked 3 times. This device is not subject to the SPI slave CSn errata of this familly.
Does anyone see what I do wrong ? or have a working example as SLAVE ?
// Setup hardware I/Os configuration
SPI_SLAVE_CSN_TRIS = 1; //input
SPI_SLAVE_CLK_TRIS = 1;
SPI_SLAVE_MOSI_TRIS = 1;
SPI_SLAVE_MISO_TRIS = 0; //output
// Setup remapable pins
SPI_SLAVE_MISO_RPN = _RPOUT_SDO2; // configure RP output
RPINR22bits.SDI2R = SPI_SLAVE_MOSI_RP_NUMBER; //configure inputs
RPINR22bits.SCK2R = SPI_SLAVE_CLK_RP_NUMBER;
RPINR23bits.SS2R = SPI_SLAVE_CSN_RP_NUMBER;
IFS2bits.SPI2IF = 0; // Clear interrupt flag
IEC2bits.SPI2IE = 0; // Disable interrupt
// Baudrate configuration (unused in slave mode )
SPI2CON1bits.PPRE = 0b11; //TODO needed in slave mode ?
SPI2CON1bits.SPRE = 0b110;
SPI2CON1bits.DISSCK = 0; // Internal serial clock
SPI2CON1bits.DISSDO = 0; // SDOx is controlled by the module
SPI2CON1bits.MODE16 = 0; // 8 bit mode //TODO check if 16 bit fit's better
SPI2CON1bits.SMP = 0; // 0 when slave
SPI2CON1bits.CKE = 1; // Emits SDO on SCK falling edge (slave samples on rising)
SPI2CON1bits.CKP = 0; // SCK idle state is LOW level
SPI2CON1bits.SSEN = 1;// CSN pin used for slave mode
SPI2CON1bits.MSTEN = 0; // Slave mode is enabled
//SPI2CON2bits.SPIFSD = 1; //we are not in framed mode
SPI2STATbits.SPIEN = 1; // Enable SPI module
//TODO ISR priority
// Write the SPIx Interrupt Priority Control (SPIxIP) bits in the respective IPCx register to set the interrupt priority
SPI2BUF = 0xf3; // Clear data to be transmitted => for test
IFS2bits.SPI2IF = 0; // Clear interrupt flag
IEC2bits.SPI2IE = 1; // Enable interrupt
SOLVED
The RPN pin fucntions where locked in another part of the code I hadn't written.
I was not aware of this functionnality
I have no experience with SPI in slave mode but in general setting the priority of the interrupt on 16 and 32 bit pic MCUs are not optional, it must be set or the interrupt won't fire, at least that's been my experience. Set the IPCx bits relevant for the peripherals you use.
Try finding a code snippet where an interrupt function is defined and use that as a template. It's generally very similar for every peripheral. UART and maybe also the SPI module has a separate send and receive interrupt vector, both must be defined.
Somewhere in the main function, enable the interrupt and set the priority, at least non zero IIRC:
IEC0bits.AD1IE = 1; // Enable adc interrupt
IPC3bits.AD1IP = 4; // set priority above that of the serial port.
For an ADC I use this to define the interrupt. All you need to change is the _ADC1Interrupt part. See the datasheet and XC16 documentation for the correct function name.
// ADC1 interrupt vector
void __attribute__((__interrupt__(auto_psv))) _ADC1Interrupt(void)
{
if( IFS0bits.AD1IF ) // Check interrupt flag
{
}
IFS0bits.AD1IF = 0; // clear interrupt flag to prevent endless interrupts
}

ADI BF533 programmable flag interrupt

When I press PF8 button, I want the blackfin goes into a ISR and the counter increases 1.
I should clear or set a bit which indicates the processor has entered the ISR, but I don't know how to clear it.
My processor is BF533.
Here is my code:
// prototype
EX_INTERRUPT_HANDLER(FlagA_ISR);
volatile int count = 0;
void main(void)
{
// Register FlagA ISR to interrupt vector group 12
register_handler(ik_ivg12, FlagA_ISR);
// set direction of programmable flag PF8 to input
*pFIO_DIR &= ~PF8;
ssync();
// interrupt enable PF8
*pFIO_INEN |= PF8;
ssync();
// give interrupt when FIO_FLAG_D PF8 changes
*pFIO_MASKA_D |= PF8;
ssync();
// Bind FlagA interrupt to IVG12
*pSIC_IAR2 |= 0x00005000; // flag A IVG12
ssync();
// Enable PFA in system interrupt mask register
*pSIC_IMASK = 0x00080000;
ssync();
// enable IVG12 in core interrupt mask register
*pIMASK |= 0x00001000;
ssync();
// wait for interrupt
while(count < 5);
printf("5 interrupts received");
}
EX_INTERRUPT_HANDLER(FlagA_ISR)
{
count++;
// Needed to clear or set a bit to indicate that the processor has entered the ISR
}
I have just figured out how to solve this question.
The PFx are connected to the FIO_FLAG. We can clear our interrupt status by clearing FIO_FLAG.
Here is the code:
*pFIO_FLAG_D &= ~PF8;
ssync();
//or, you can try:
*pFIO_FLAG_C |= PF8;
ssync();