Ϊʲôͬһ³ÌÐòÔÚSTM32Éϲ»ÄÜÔËÐÐ ÔÚMSP430ÉÏÄÜÔËÐÐ
ʱ¼ä£º10-02
ÕûÀí£º3721RD
µã»÷£º
ͬÑùµÄ³ÌÐò£¬ÔÚSTM32Éϲ»ÄÜÔËÐÐ ÔÚMSP430ÉÏÄÜÔËÐÐ
Á½¸ö´úÂëÊǷdz£µÄÏàËÆ£¬µ«ÊÇMSP430Àï¶Á³ö ״̬¼Ä´æÆ÷=0x02£¬STM32¶Á³öµÄÊý¾Ý»á·¢Éú±ä»¯£¬²»ÖªµÀÊÇʲôÔÒò¡£
ÏÂÃæ·Ö±ðÌù´úÂ룬ϣÍû´ó¼ÒÄÜÖ¸µãÖ¸µã£¡
MSP430ϵijÌÐò£¬²Î¿¼±ðÈ˵Ä
[color=rgb(51, 102, 153) £¡important]¸´ÖÆ´úÂë
STM32ϵijÌÐò£º
[color=rgb(51, 102, 153) £¡important]¸´ÖÆ´úÂë
[color=rgb(51, 102, 153) £¡important]¸´ÖÆ´úÂë
Á½¸ö´úÂëÊǷdz£µÄÏàËÆ£¬µ«ÊÇMSP430Àï¶Á³ö ״̬¼Ä´æÆ÷=0x02£¬STM32¶Á³öµÄÊý¾Ý»á·¢Éú±ä»¯£¬²»ÖªµÀÊÇʲôÔÒò¡£
ÏÂÃæ·Ö±ðÌù´úÂ룬ϣÍû´ó¼ÒÄÜÖ¸µãÖ¸µã£¡
MSP430ϵijÌÐò£¬²Î¿¼±ðÈ˵Ä
- #define MB85SR64_DLY 30
- #define MB85RS64_PORT_IN P2IN
- #define MB85RS64_PORT_OUT P2OUT
- #define MB85RS64_CS BIT0
- #define MB85RS64_WP BIT5
- #define MB85RS64_SCK BIT3
- #define MB85RS64_SI BIT2
- #define MB85RS64_SO BIT1
- #define SET_MB85RS64_CS MB85RS64_PORT_OUT|=MB85RS64_CS
- #define SET_MB85RS64_WP MB85RS64_PORT_OUT|=MB85RS64_WP
- #define SET_MB85RS64_SCK MB85RS64_PORT_OUT|=MB85RS64_SCK
- #define SET_MB85RS64_SI MB85RS64_PORT_OUT|=MB85RS64_SI
- #define SET_MB85RS64_SO MB85RS64_PORT_OUT|=MB85RS64_SO
- #define CLR_MB85RS64_CS MB85RS64_PORT_OUT&=~MB85RS64_CS
- #define CLR_MB85RS64_WP MB85RS64_PORT_OUT&=~MB85RS64_WP
- #define CLR_MB85RS64_SCK MB85RS64_PORT_OUT&=~MB85RS64_SCK
- #define CLR_MB85RS64_SI MB85RS64_PORT_OUT&=~MB85RS64_SI
- #define CLR_MB85RS64_SO MB85RS64_PORT_OUT&=~MB85RS64_SO
- #define Read_MB85RS64_SO (MB85RS64_PORT_IN&MB85RS64_SO)==MB85RS64_SO
- //¼Ä´æÆ÷Ïà¹Ø
- #define MB85RS64_WREN 0x06//Set Write Enable Latch 0000 0110
- #define MB85RS64_WRDI 0x04//Reset Write Enable Latch 0000 0100B
- #define MB85RS64_RDSR 0x05//Read Status Register 0000 0101B
- #define MB85RS64_WRSR 0x01//Write Status Register 0000 0001B
- #define MB85RS64_READ 0x03//Read Memory Code 0000 0011B
- #define MB85RS64_WRITE 0x02//Write Memory Code 0000 0010B
- void Write_data(unsigned int address,unsigned char * data,unsigned int number)
- {
- unsigned int temp_address=0;
- unsigned char i=0;
- //Set Write Enable Latch
- CLR_MB85RS64_CS;
- Write(MB85RS64_WREN);
- SET_MB85RS64_CS;
- temp_address=address&0x1FFF;
- //Write Memory Code
- CLR_MB85RS64_CS;
- Write(MB85RS64_WRITE);
- Write((temp_address>>8)&0xFF);
- Write(temp_address&0xFF);
- for(i=0;i<number;i++)
</number;i++) - {
- Write(* data);
- data++;
- }
- SET_MB85RS64_CS;
- }
- void Read_data(unsigned int address,unsigned char * data,unsigned int number)
- {
- unsigned int temp_address=0;
- unsigned char i=0;
- temp_address=address&0x1FFF;
- //Read Memory Code
- CLR_MB85RS64_CS;
- Write(MB85RS64_READ);
- Write((temp_address>>8)&0xFF);
- Write(temp_address&0xFF);
- for(i=0;i<number;i++)
</number;i++) - {
- * data=Read();
- data++;
- }
- SET_MB85RS64_CS;
- }
- void Init_PORT(void)
- {
- P2OUT = 0x00; P2SEL &= 0xD0;
- P2SEL2 &= 0xD0;
- P2DIR |= BIT0 + BIT2 + BIT3 + BIT5; //
- P2DIR &= ~BIT1; //
- P2REN |= BIT1;
- }
- void main(void)
- {
- volatile unsigned int i;
- char uart_tx_buf[30];
- unsigned char rd_data;
- unsigned char rd;
- unsigned char rd_test = 0;
- WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
- Init_PORT();
- Init_uart0();
- sendStr("Init\n");
- Init_PORT();
- while(1)
- {
- //Set Write Enable Latch
- CLR_MB85RS64_CS;
- Write(MB85RS64_WREN);
- SET_MB85RS64_CS;
- //Read
- CLR_MB85RS64_CS;
- Write(MB85RS64_RDSR);
- rd_data=Read();
- SET_MB85RS64_CS;
- sprintf(uart_tx_buf,"stat1==0x%02X\n",rd_data);
- sendStr(uart_tx_buf);
- //Set Write Enable Latch
- CLR_MB85RS64_CS;
- Write(MB85RS64_WRDI);
- SET_MB85RS64_CS;
- //Read
- CLR_MB85RS64_CS;
- Write(MB85RS64_RDSR);
- rd_data=Read();
- SET_MB85RS64_CS;
- sprintf(uart_tx_buf,"stat1==0x%02X\n",rd_data);
- sendStr(uart_tx_buf);
- DelayXms(1000);
- }
- }
[color=rgb(51, 102, 153) £¡important]¸´ÖÆ´úÂë
STM32ϵijÌÐò£º
- #define CLR_MB85RS64_CS GPIO_WriteBit(GPIOC, SPI_MB85RS64_CS, Bit_RESET)
- #define SET_MB85RS64_CS GPIO_WriteBit(GPIOC, SPI_MB85RS64_CS, Bit_SET)
[color=rgb(51, 102, 153) £¡important]¸´ÖÆ´úÂë
- void MySPI_GPIO_Init(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_APB2PeriphClockCmd(SPI_GPIO_RCC, ENABLE);
- GPIO_InitStructure.GPIO_Pin = SPI_SCK | SPI_MOSI;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_Init(SPI_PORT, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = SPI_MISO;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
- //GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_Init(SPI_PORT, &GPIO_InitStructure);
- GPIO_SetBits(SPI_PORT, SPI_SCK | SPI_MOSI);
- }
- unsigned char Read(void)
- {
- unsigned char i=0,data=0;
- GPIO_WriteBit(SPI_PORT, SPI_SCK, Bit_RESET);
- for(i=0;i<8;i++)
- {
- data<<=1;
- GPIO_WriteBit(SPI_PORT, SPI_SCK, Bit_SET);;
- DelayXus(MB85SR64_DLY);
- //if(Read_MB85RS64_SO)
- if(GPIO_ReadInputDataBit(SPI_PORT, SPI_MISO))
- {data|=1;}
- GPIO_WriteBit(SPI_PORT, SPI_SCK, Bit_RESET);
- DelayXus(MB85SR64_DLY);
- }
- return data;
- }
- void Write(unsigned char data)
- {
- unsigned char i=0;
- GPIO_WriteBit(SPI_PORT, SPI_SCK, Bit_RESET);
- for(i=0;i<8;i++)
- {
- if((data&0x80)==0x80)
- {GPIO_WriteBit(SPI_PORT, SPI_MOSI, Bit_SET);}
- else
- {GPIO_WriteBit(SPI_PORT, SPI_MOSI, Bit_RESET);}
- data<<=1;
- GPIO_WriteBit(SPI_PORT, SPI_SCK, Bit_SET);
- DelayXus(MB85SR64_DLY);
- GPIO_WriteBit(SPI_PORT, SPI_SCK, Bit_RESET);
- }
- }
- MySPI_GPIO_Init();
- MySPI_MB85RS64_CS_Init();
- MySPI_MB85RS64_CS_H;
- while(1)
- {
- //Set Write Enable Latch
- CLR_MB85RS64_CS;
- Write(MB85RS64_WREN);
- SET_MB85RS64_CS;
- //Read
- CLR_MB85RS64_CS;
- Write(MB85RS64_RDSR);
- rd_data=Read();
- SET_MB85RS64_CS;
- printf("stat1==0x%02X\n",rd_data);
- //Set Write Enable Latch
- CLR_MB85RS64_CS;
- Write(MB85RS64_WRDI);
- SET_MB85RS64_CS;
- //Read
- CLR_MB85RS64_CS;
- Write(MB85RS64_RDSR);
- rd_data=Read();
- SET_MB85RS64_CS;
- printf("stat2==0x%02X\n",rd_data);
- DelayXms(1000);
- }
[color=rgb(51, 102, 153) £¡important]¸´ÖÆ´úÂë
ÔÚ²»Í¬Æ½Ì¨ÒÆֲͬÑùµÄ´úÂëʵÏÖ²¢²»Ò»¶¨»áÒ»Ñù ±ÈÈç DelayXms(1000);ÔÚmsp430ºÍSTM32ÉÏÔËÐнá¹û¾Í²»Ò»Ñù Ö»ÄÜ×÷Ϊ²Î¿¼ ×îÖ÷ÒªµÄ»¹ÊÇ¿´MB85RS64ÊÖ²á Ñϸñ°´ÕÕÊÖ²áµÄʱÐòÀ´ÊµÏÖ´úÂë
LZ,ÄãÒªÇå³þ£¬MSP430ºÍSTM32ÊÇÁ½¿î²»Í¬µÄоƬ£¬¿ÉÒÔ˵¸ù±¾²»Ò»Ñù£¬ÄãÔõô¿ÉÒÔÒ»¸ö³ÌÐòÁ½¸ö¶¼¿ÉÐÐÄØ?²»ÒªËµMSP430µÄ³ÌÐòÒÆÖ²µ½STM32оƬÉÏ£¬ÓÐЩÊÇͬ³§¼Ò²»Í¬ÐͺŵÄоƬ³ÌÐò¶¼²»ÄÜÒÆÖ²£¬ËûÃǵļĴæÆ÷ÓÐЩ²»Ò»Ñù
ÔÀ´ÊÇÕâÑù°¡ ¶®ÁË Ð»Ð»