This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/MSP430FR4133: msp430FR4133

Part Number: MSP430FR4133

Tool/software: Code Composer Studio

i am trying to work PCF8583 on msp430fr4133. date and time correct display but alarm problem.10 second alarm is set,after first 10 second INT pin(pin no 7) of pcf goes low but program not goes to interrupt routine and INT pin remain low.

Here is my code....

#include "driverlib.h"
#include "Board.h"
#include <sw_i2c.h>

//#include "Board.h"

// Define word access definitions to LCD memories
#define pos1 1 /* Digit A1 - L4 */
#define pos2 2 /* Digit A2 - L6 */
#define pos3 3 /* Digit A3 - L8 */
#define pos4 4 /* Digit A4 - L10 */
const char digit1[10];
extern const char digit[10];

//volatile unsigned char * mode = &BAKMEM4_L;
void Init_LCD(void);
void diplay(uint8_t num,int posi);
void display_time();
void display_date();
void display_temp(float t);
void Setsecondsalarm(int value);
void restartAlarm();

//void uart_init();
uint8_t rec_buffer1[5];
uint8_t (*ptr1)[5];
uint8_t rec_buffer2[5];
uint8_t (*ptr2)[5];
//================================================rtc==============================================================================
uint8_t address=0xA0>>1;
uint8_t dow;
uint8_t second=10;
uint8_t minute=58;
uint8_t hour=04;
uint8_t day=16;
uint8_t month=11;
int year=2018;
int year1=0;
uint8_t year_base=2016;
uint8_t setsec=5,setmin=2,sethr=2;
int bcd_to_byte(uint8_t bcd);
uint8_t int_to_bcd(int in);
void get_time();
void set_time();
int AM;



void interrupt_set();
/* int alarm_milisec;
int alarm_second;
int alarm_minute;
int alarm_hour;
int alarm_day; */
uint8_t _i2caddr=0x28;
uint8_t status;
float humidity;
float temperatureC;
float temperatureF;

int main(void) {

WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer


interrupt_set();
I2C_Init();
Init_LCD();

PMM_unlockLPM5();

set_time();

Setsecondsalarm(setsec);

// Setminutesalarm(setmin);
// Sethoursalarm(sethr);
// set_daily_alarm();


while(1){

get_time();

//__delay_cycles(80000);
display_time();
// display_date();


if(AM==1){



Setsecondsalarm(setsec);
// __delay_cycles(80000);


AM=2;
}

__delay_cycles(1000);
__bis_SR_register(GIE);

}


}


#pragma vector=PORT1_VECTOR
__interrupt void P1_ISR (void)

{ if(P1IFG&BIT3){


GPIO_toggleOutputOnPin(GPIO_PORT_P4,GPIO_PIN0);

GPIO_clearInterrupt(GPIO_PORT_P1,GPIO_PIN3);
__delay_cycles(2000);

AM=1;



}

void interrupt_set(){

GPIO_setAsOutputPin(GPIO_PORT_P4,GPIO_PIN0);
GPIO_setOutputLowOnPin(GPIO_PORT_P4,GPIO_PIN0);
GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1,GPIO_PIN3);
// GPIO_setAsInputPin(GPIO_PORT_P1,GPIO_PIN3);
GPIO_enableInterrupt(GPIO_PORT_P1,GPIO_PIN3);
// GPIO_selectInterruptEdge(GPIO_PORT_P1,GPIO_PIN3,GPIO_LOW_TO_HIGH_TRANSITION);
GPIO_selectInterruptEdge(GPIO_PORT_P1,GPIO_PIN5,GPIO_HIGH_TO_LOW_TRANSITION);
GPIO_clearInterrupt(GPIO_PORT_P1,GPIO_PIN3);



}


void get_time(){
uint8_t rec_buffer[5];
uint8_t (*ptr)[5];
ptr = &rec_buffer;
uint8_t Register;
// uint8_t Register12;
ptr1 = &rec_buffer1;
uint8_t yr;

rec_buffer[0]=0;
Register=0xC0;
I2C_WriteData(*ptr,address,Register, 1);


Register=0x10;
I2C_ReadData(*ptr,address,Register,1);
year1 = (rec_buffer[1])<<8;
year1 = (year1 | (rec_buffer[0]));


rec_buffer[0]=0;
Register=0xFF;
I2C_WriteData(*ptr,address,Register, 1);

// __delay_cycles(2000);

Register=0x02;
I2C_ReadData(*ptr,address,Register, 5);
second = bcd_to_byte(rec_buffer[0]);
minute = bcd_to_byte(rec_buffer[1]);
hour = bcd_to_byte(rec_buffer[2]);


uint8_t incoming = rec_buffer[3]; // year/date counter
day = bcd_to_byte(incoming & 0x3f); //3f

year = (int)((incoming >> 6) & 0x03); // it will only hold 4 years...
incoming = rec_buffer[4];
month = bcd_to_byte(incoming & 0x1f);
dow = incoming >> 5;

year = year + year1;


}

int bcd_to_byte(uint8_t bcd){
return ((bcd >> 4) * 10) + (bcd & 0x0f);
}

uint8_t int_to_bcd(int in){
return ((in / 10) << 4) + (in % 10);
}


void set_time()
{ uint8_t rec_buffer[5];
uint8_t (*ptr)[5];
ptr = &rec_buffer;
uint8_t Register;

ptr1 = &rec_buffer1;

/*if (!IsLeapYear(year) && 2 == month && 29 == day) {
month = 3;
day = 1;
}*/

// Attempt to find the previous leap year
/*year_base = year -(year % 4);
if (!IsLeapYear(year_base)) {
// Not a leap year (new century), make sure the calendar won't use a 29 days February.
year_base = year - 1;
}*/

// dow = DayOfWeek(*this);


rec_buffer[0]=0;
Register=0xC0;
I2C_WriteData(*ptr,address,Register, 1);

Register=0x10;
// rec_buffer1[0]=(2000-( year - (year % 4)))>>8;
//rec_buffer1[1]=((int)year_base & 0x00ff);
// I2C_WriteData(*ptr1,address,Register, 2);
rec_buffer1[1]=( (( year - (year % 4)))>>8);//<< 8);//0x07;//<<
rec_buffer1[0]=( (year - (year % 4)) & 0x00ff);//0xE0;//
I2C_WriteData(*ptr1,address,Register, 2);
rec_buffer2[0]=bcd_to_byte(rec_buffer1[0]);//bcd_to_byte(rec_buffer1[0]);
//rec_buffer2[1]=bcd_to_byte(rec_buffer1[1]);


Register=0x02;
rec_buffer[0]=(int_to_bcd(second));
rec_buffer[1]=(int_to_bcd(minute));
rec_buffer[2]=(int_to_bcd(hour));
rec_buffer[3]=(((int)(year - year_base) << 6) | int_to_bcd(day) );
//rec_buffer[3]=(int)((year << 6) & 0x03) | ( int_to_bcd(day) & 0x1f);
rec_buffer[4]=((dow << 5) | (int_to_bcd(month) & 0x1f));
I2C_WriteData(*ptr,address,Register, 5);


}


bool IsLeapYear(int year) {
return !(year % 400) || ((year % 100) && !(year % 4));
}


/*uint8_t DayOfWeek() {
static char PROGMEM MonthTable[24] = {0, 3, 3, 6, 1, 4, 6, 2, 5, 0, 3, 5, -1, 2, 3, 6, 1, 4, 6, 2, 5, 0, 3, 5};
uint8_t y = year % 100, c = 6 - 2 * ((year / 100) % 4);
return (day + pgm_read_byte_near(MonthTable + IsLeapYear(year) * 12 + month - 1) + y + (y / 4) + c) % 7;
} */


void Setsecondsalarm(int value){
uint8_t rec_buffer[5];
uint8_t (*ptr)[5];
ptr = &rec_buffer;
uint8_t Register;
//control and status register
Register=0x00;
rec_buffer[0]=0x04;
I2C_WriteData(*ptr,address,Register, 1);
__delay_cycles(80);
//alarm control register
Register=0x08;
rec_buffer[0]=0x4A;
I2C_WriteData(*ptr,address,Register, 1);
__delay_cycles(80);
//preset value
Register=0x0F;
rec_buffer[0]=(int_to_bcd(99-value));
I2C_WriteData(*ptr,address,Register, 1);
__delay_cycles(80);
Register=0x07;
rec_buffer[0]=(int_to_bcd(99-value));
I2C_WriteData(*ptr,address,Register, 1);
__delay_cycles(80);
}


void restartAlarm(){
uint8_t rec_buffer[5];
uint8_t (*ptr)[5];
ptr = &rec_buffer;
uint8_t Register;
//control and status register
Register=0x00;
rec_buffer[0]=0x04; //0x05
I2C_WriteData(*ptr,address,Register, 1);
__delay_cycles(80);

Register=0x07;
rec_buffer[0]=(int_to_bcd(99-5));
I2C_WriteData(*ptr,address,Register, 1);
__delay_cycles(80);

}

//========================================================lcd====================================================================

// used for lcd position 5,6,7,8,9,10
const char digit[10] = {
0xFA, /* "0" */
0x60, /* "1" */
0xBC, /* "2" */
0xF4, /* "3" */
0x66, /* "4" */
0xD6, /* "5" */
0xDE, /* "6" */
0x72, /* "7" */
0xFE, /* "8" */
0xF6 /* "9" */
};
//used for lcd position 1,2,3,4
const char digit1[10] =
{
0xF5, // "0"
0x60, // "1"
0xD3, // "2"
0xF2, // "3"
0x66, // "4"
0xB6, // "5"
0xB7, // "6"
0xE4, // "7"
0xF7, // "8"
0xF6 // "9"
};

void Init_LCD()
{
// L0~L26 & L36~L39 pins selected
LCD_E_setPinAsLCDFunctionEx(LCD_E_BASE, LCD_E_SEGMENT_LINE_0, LCD_E_SEGMENT_LINE_26);
LCD_E_setPinAsLCDFunctionEx(LCD_E_BASE, LCD_E_SEGMENT_LINE_36, LCD_E_SEGMENT_LINE_39);

LCD_E_initParam initParams = LCD_E_INIT_PARAM;
initParams.clockDivider = LCD_E_CLOCKDIVIDER_3;
initParams.muxRate = LCD_E_4_MUX;
initParams.segments = LCD_E_SEGMENTS_ENABLED;
initParams.waveforms= LCD_E_LOW_POWER_WAVEFORMS;
// Init LCD as 4-mux mode
LCD_E_init(LCD_E_BASE, &initParams);

// LCD Operation - Mode 3, internal 3.02v, charge pump 256Hz
LCD_E_setVLCDSource(LCD_E_BASE, LCD_E_INTERNAL_REFERENCE_VOLTAGE, LCD_E_EXTERNAL_SUPPLY_VOLTAGE);
LCD_E_setVLCDVoltage(LCD_E_BASE, LCD_E_REFERENCE_VOLTAGE_2_96V);

LCD_E_enableChargePump(LCD_E_BASE);
LCD_E_setChargePumpFreq(LCD_E_BASE, LCD_E_CHARGEPUMP_FREQ_16);

// Clear LCD memory
LCD_E_clearAllMemory(LCD_E_BASE);

// Configure COMs and SEGs
// L0 = COM0, L1 = COM1, L2 = COM2, L3 = COM3
LCD_E_setPinAsCOM(LCD_E_BASE, LCD_E_SEGMENT_LINE_0, LCD_E_MEMORY_COM0);
LCD_E_setPinAsCOM(LCD_E_BASE, LCD_E_SEGMENT_LINE_1, LCD_E_MEMORY_COM1);
LCD_E_setPinAsCOM(LCD_E_BASE, LCD_E_SEGMENT_LINE_2, LCD_E_MEMORY_COM2);
LCD_E_setPinAsCOM(LCD_E_BASE, LCD_E_SEGMENT_LINE_3, LCD_E_MEMORY_COM3);

// Select to display main LCD memory
LCD_E_selectDisplayMemory(LCD_E_BASE, LCD_E_DISPLAYSOURCE_MEMORY);

// Turn on LCD
LCD_E_on(LCD_E_BASE);
}


void diplay(uint8_t num,int posi){
uint8_t lower,higher;
lower=num/10;
higher=num-lower*10;
switch(posi){
case 1:
{
LCDM8 = digit[lower];
LCDM9 = digit[higher];
break;
}
case 2:{
LCDM10 = digit[lower];
LCDM11 = digit[higher];
break;
}
case 3:{
LCDM2 = digit[lower];
LCDM3 = digit[higher];
break;
}
}

}

void display_temp(float t){
uint16_t temp,t1,t2,t3,t4;
temp=t*10;
t1=temp/1000;
t2=(temp-(t1*1000))/100;
t3=(temp-(t1*1000)-(t2*100))/10;
t4=(temp-(t1*1000)-(t2*100)-(t3*10));
LCDM4 = digit1[t1];
LCDM5 = digit1[t2];
LCDM6 = digit1[t3];
LCDM7 = digit1[t4];
LCDM7=LCDM7|(0x08);
}

void display_time(){
diplay(hour ,pos1);
diplay(minute,pos2);
diplay(second,pos3);
LCDM10= LCDM10|0x01;
LCDM2= LCDM2|0x01;
LCDM8= LCDM8|0x01;
}
void display_date(){
// year1=(year>>8);
// year2=(year & 0x00FF);
year1=year-0x7D0;
diplay(day,pos1);
diplay(month,pos2);
diplay(year1,pos3);
LCDM10= LCDM10|0x01;
LCDM2= LCDM2|0x01;
//LCDM9= LCDM8|0x01;
}

  • Hi

    I think you may do the wrong GPIO settings. Why you use PIN3 as interrupt input pin, but configure PIN5?

    // GPIO_selectInterruptEdge(GPIO_PORT_P1,GPIO_PIN3,GPIO_LOW_TO_HIGH_TRANSITION);
    GPIO_selectInterruptEdge(GPIO_PORT_P1,GPIO_PIN5,GPIO_HIGH_TO_LOW_TRANSITION);

    Best Regards,
    Winter Yu

**Attention** This is a public forum