|
MR25H10这个系列的资料网上很少,最近在调试SPI通信。短接MSP430的RX,TX。调试程序,没问题。说明初始化正确。可是正常调试,发送数据到MR25H10里。返回观察就不行。好像根本就写不进去。程序现在只是简单的修改MR25H10的状态寄存器。然后把状态寄存器的值读出来,发送到430里,并显示。可是就是不对。返回值是0x00.大家有没有调试过MR25H10这个系列的。分享一下。谢谢!
#include <msp430f6779.h>
void Init_Lcd(void); //lcd系统初始化
void Init_Ucs(void); //msp430的系统初始化
void Lcd_Display(void); //显示函数
//void TIMER_A0(void); //定时器A0初始化
char Hour = 0,Minute = 0 ,Second = 0;
unsigned char MST_Data, SLV_Data;
void dis(void);
//void Init_Rtc(void);
void Init_Spi_B1(void);
//void Write_Mr25h10(int addr,unsigned char indata);
//void Read_Mr25h10(int addr);
void Read_Sr(void);
/*********************************************************
// ACLK = ~32.768kHz, MCLK = SMCLK = DCO ~ 1048kHz. BRCLK = SMCLK/2
/ MSP430F67791
// -----------------
// /|\ | |
// | | |
// +->|RST P1.0|-> LED
// | |
// | P4.5|-> Data Out (UCA0SIMO)
// | |
// | P4.4|<- Data In (UCA0SOMI)
// | |
// | P4.6|-> Serial Clock Out (UCA0CLK)
// | |
// | P4.7| -> CS
*************************************************************/
/************ Segment LCD Code Map***********/
const unsigned char LCD_Char_Map[] =
{
BIT0 | BIT1 | BIT2 | BIT3 | BIT4 | BIT6, // '0'
BIT4 | BIT6, // '1'
BIT0 | BIT1 | BIT3 | BIT5 |BIT6, // '2'
BIT0 | BIT3 | BIT4 | BIT5 | BIT6, // '3'
BIT2 | BIT4 | BIT5 | BIT6, // '4'
BIT0 | BIT2 | BIT3 | BIT4 | BIT5, // '5'
BIT0 | BIT1 | BIT2 | BIT3 | BIT4 | BIT5, // '6'
BIT3 | BIT4 | BIT6, // '7'
BIT0 | BIT1 | BIT2 | BIT3 |BIT4 | BIT5 | BIT6, // '8'
BIT0 | BIT2 | BIT3 |BIT4 | BIT5 | BIT6, // '9'
};
void Init_Lcd(void)
{
// Setup LCD_C
// LCD_FREQ = ACLK/32/4, LCD Mux 4, turn on LCD
// LCD_BLK_FREQ = ACLK/512
LCDCCTL0 = LCDDIV_31 | LCDPRE_1 | LCD4MUX | LCDON;//LCD_C Control Register初始化,设置LCD的时钟频率,工作模式,并且打开LCD
//Charge pump generated internally at 2.96V, external bias (V2-V4) generation
//Internal reference for charge pump
//LCD_C Voltage Control Register
LCDCVCTL = LCDCPEN | VLCD_2_60;
LCDCPCTL0 = 0XFFFF; //SELECT LCD SEGMENT 0-23
LCDCPCTL1 = 0X00FF;
//LCDCBLKCTL = LCDBLKPRE2_L | LCDBLKPRE0_L | LCDBLKMOD_1 ; /* LCD_C Blinking mode: Individual */
}
void Init_Ucs(void)
{
// Initialize LFXT1
UCSCTL6 &= ~(XT1OFF); // Enable XT1
UCSCTL6 |= XCAP_3; // Internal load cap
// Loop until XT1, XT2 & DCO fault flag is cleared
do
{
UCSCTL7 &= ~(XT2OFFG | XT1LFOFFG | DCOFFG);
// Clear XT2,XT1,DCO fault flags
SFRIFG1 &= ~OFIFG; // Clear fault flags
} while (SFRIFG1 & OFIFG); // Test oscillator fault flag
// UCSCTL3 |= SELREF_2; // Set DCO FLL reference = REFO
// UCSCTL4 |= SELA_2; // Set ACLK = REFO
//UCSCTL4 |= SELA1 + SELA0 ; // ACLK = 011b DCOCLK
// UCSCTL4 |= SELA1 ; //ACLK = 010 REFOCLK
}
void Init_Spi_B1(void)
{
// Setup P4.7 output, P3.0 UCA0SOMI, P3.1 UCA0SIMO, P3.2 UCA0CLK
P4OUT &= ~BIT7; // Clear P4.7
P4DIR |= BIT7; // Set P4.7 to output direction
P4SEL0 |= BIT4 | BIT5 | BIT6; // Set P4.4,P4.5,P4.6 to non-IO
// Setup eUSCI_B1
UCB1CTLW0 |= UCSWRST; // **Put state machine in reset**
UCB1CTLW0 |= UCMST | UCSYNC | UCCKPL | UCMSB;// 3-pin, 8-bit SPI master
// Clock polarity high, MSB
UCB1CTLW0 |= UCSSEL_2; // SMCLK
UCB1BRW_L = 0x02; // /2
UCB1BRW_H = 0; //
//UCB1MCTLW = 0; // No modulation
UCB1CTLW0 &= ~UCSWRST; // **Initialize USCI state machine**
UCB1IE = UCRXIE ; // Enable USCI_B1 RX,TX interrupt
__delay_cycles(100); // Wait for slave to initialize
}
void Read_Sr(void)
{
// MST_Data = 0x01; // Initialize data values
P4OUT |= BIT7 ; //拉高CS
__delay_cycles(500);
P4OUT &= ~BIT7; //拉低CS
while (!(UCB1IFG & UCTXIFG)) ; // USCI_A0 TX buffer ready?
UCB1IFG &= ~UCTXIFG ; //发送中断标志位清零
UCB1TXBUF = 0x06; // MR25H10 WREN
__delay_cycles(20);
while (!(UCB1IFG & UCTXIFG)) ; // USCI_A0 TX buffer ready?
__delay_cycles(20);
//P4OUT |= BIT7 ; //拉高CS
__delay_cycles(500);
//P4OUT &= ~BIT7; //拉低CS
while (!(UCB1IFG & UCTXIFG)) ; // USCI_A0 TX buffer ready?
UCB1IFG &= ~UCTXIFG ; //发送中断标志位清零
UCB1TXBUF = 0x01; // MR25H10 WRSR
__delay_cycles(11);
while (!(UCB1IFG & UCTXIFG)) ; // USCI_A0 TX buffer ready?
UCB1IFG &= ~UCTXIFG ; //发送中断标志位清零
UCB1TXBUF = 0x12; // MR25H10 DATA
while (!(UCB1IFG & UCTXIFG)) ; // USCI_A0 TX buffer ready?
__delay_cycles(20);
P4OUT |= BIT7 ; //拉高CS
//__delay_cycles(200);
// P4OUT |= BIT7 ; //拉高CS
__delay_cycles(200);
P4OUT &= ~BIT7; //拉低CS
while (!(UCB1IFG & UCTXIFG)) ; // USCI_A0 TX buffer ready?
UCB1IFG &= ~UCTXIFG ; //发送中断标志位清零
UCB1TXBUF = 0x05; // MR25H10 DATA
while (!(UCB1IFG & UCTXIFG)) ;
// __delay_cycles(20);
}
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
Init_Ucs(); //Set system clock
Init_Lcd(); //Lcd Init
Init_Spi_B1(); //Init_Spi
LCDM1 |= BIT7;
LCDM2 |= BIT7;
__bis_SR_register(GIE); // Enter LPM0 w/ interrupt
Read_Sr();
//Write_Mr25h10(0x0001,0x17);
//Read_Mr25h10(0x0001);
while (1)
{
dis();
}
}
// USCI_B1 interrupt service routine
#pragma vector=USCI_B1_VECTOR
__interrupt void USCI_B1_ISR(void)
{
switch (__even_in_range(UCB1IV, 4))
{
case USCI_NONE: break; // No interrupt
case USCI_SPI_UCRXIFG: // RXIFG
//while (!(UCB1IFG & UCTXIFG)) ; // USCI_A0 TX buffer ready?
Second = UCB1RXBUF ;
dis();
__delay_cycles(500);
break;
case USCI_SPI_UCTXIFG:
UCB1IFG &= ~UCTXIFG ; //发送中断标志位清零
__no_operation();
break; // TXIFG
default: break;
}
}
void dis(void)
{
LCDM12 = LCD_Char_Map[0]; //Hour 高位
LCDM11 = LCD_Char_Map[0]; //Hour 低位
LCDM10 = LCD_Char_Map[0]; //Minute 高位
LCDM9 = LCD_Char_Map[0]; //Minute 低位
LCDM8 = LCD_Char_Map[Second / 16]; //Second 高位
LCDM7 = LCD_Char_Map[Second % 16]; //Second 低位
} |
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|