比较关注我们家庭物联网的网友都会有个疑问,很多人都没在做富士通,在做430。其实我们是有原因的,因为物联网注定了我们需要网络节点,而富士通板子只有一块,所以采用了TI的430作为子节点的控制芯片。
现奉上MB9BF506R的串口通讯代码:
/*=============================================================================
[NOTE] Connected chart
-------------------------------------------------------------------------------
PC
+-----------------------+
| Baudrate : 9600 bps |
| DataBit : 8 bit |
| Parity : None | <-----> MFS Ch4@MB9BF506 Board
| StopBit : 1 bit |
| FlowCtl : None |
+-----------------------+
=============================================================================*/
#include <intrinsics.h>
#include <stdio.h>
#include <stdlib.h>
#include <Fujitsu/iomb9bf506r.h>
#include <assert.h>
/*************************************************************************
* Function Name: NVIC_IntEnable
* Parameters: IntNumber - Interrup number
* Return: void
*
* Description: Enable interrup at NVIC
*
*
*************************************************************************/
void NVIC_IntEnable(unsigned char IntNumber)
{
volatile unsigned long * pNVIC_SetEn = &SETENA0;
// assert((NVIC_FCS <= IntNumber) && (NVIC_DMA_CH7 >= IntNumber));
IntNumber -= NVIC_FCS;
pNVIC_SetEn += IntNumber/32;
*pNVIC_SetEn = (1UL<<(IntNumber%32));
}
/*************************************************************************
* Function Name: InitClock
* Parameters: void
* Return: void
*
* Description: Initialize PLL to 80MHz,
* Base Clock = 80MHz
* APB0 = APB1 = APB2 = 40MHz
*
*************************************************************************/
void InitClock(void)
{
/*set Main clock stabilization
wait time to 2ms*/
CSW_TMR_bit.MOWT = 9;
/*Enable Main Oscilator*/
SCM_CTL_bit.MOSCE = 1;
/*Wait stabilization end*/
while(!SCM_STR_bit.MORDY);
/*Set PLL stabilization
wait time to 512uS*/
PSW_TMR_bit.POWT = 2;
/*Set PLL to 80MHz*/
PLL_CTL1 = 0; /*K = 1, M=1*/
PLL_CTL2 = 19; /*N = 20*/
/*Enable PLL*/
SCM_CTL_bit.PLLE = 1;
/*Set bus prescalers*/
BSC_PSR_bit.BSR = 0; /*Base clock Prescaler 1:1*/
APBC0_PSR_bit.APBC0 = 2; /*APB0 clock Prescaler 1:2*/
APBC1_PSR_bit.APBC1 = 2; /*APB1 clock Prescaler 1:2*/
APBC2_PSR_bit.APBC2 = 2; /*APB2 clock Prescaler 1:2*/
/*Wait PLL stabilizatoin end*/
while(!SCM_STR_bit.PLRDY);
/*Select PLL for main clock*/
SCM_CTL_bit.RCS = 2;
/*Wait PLL to be connected*/
while(2 != SCM_STR_bit.RCM);
}
void MFSI_RX2_IRQHandler(void)
{
char rx_buff;
if(((UART2_SSR&0x08)>>3) == 1)
UART2_SSR = 0x80;
else
{
rx_buff=UART2_RDR;
if(rx_buff == 0xaa)
PDOR3 = 0x00;
UART2_TDR = UART2_RDR;
}
}
void MFSI_TX2_IRQHandler(void)
{
// char tx_buff;
/* if(((UART2_SSR&0x03)>>1) == 1)
{
UART2_RDR = 0xaa;
// if(rx_buff == 0x00f8)
PDOR3 = 0x00;
// else if(rx_buff == 0x00)
PDOR3 = 0x0c00;
} */
UART2_SSR = 0x80;
}
int main(void)
{
char rx_buff;
/*Unlock sequence*/
WDG_LCK = 0x1ACCE551;
WDG_LCK = 0xE5331AAE;
WDG_CTL = 0;
InitClock();
// UART2_SSR = 0x80;
PFR3 = 0x0000;
DDR3 = 0xffff;
PDOR3 = 0x0000;
/* Set Uart Ch2 Port, SIN2_1, SOT2_1 */
PFR2 |= 0x0030;
EPFR07 = 0x000a0000;
// PCR2 = 0xffff;
// DDR2 = 0xfffd;
// UART2_SCR |= 0x80;
/*Progarmmable clear,disable receive,transmit,bus idle and data reception interrupt,enable transmission*/
UART2_SCR = 0x1b;
/*MODE 0(正常模式) SIN引脚作为外部中断引脚 1位停止位 小端LSB 使能串口输出*/
UART2_SMR = 0x11;
/*不使能硬件流控制 NRZ 偶校验*/
UART2_ESCR = 0x00;
UART2_BGR = 0x0823;
NVIC_IntEnable(NVIC_MFSI_RX2);
NVIC_IntEnable(NVIC_MFSI_TX2);
while(1)
{
if(((UART2_SSR&0x04)>>2) == 1)
{
rx_buff=UART2_RDR;
if(rx_buff == 0xaa)
PDOR3 = 0x00;
else if(rx_buff == 0x00)
PDOR3 = 0x0c00;
}
// UART2_RDR = 0xaa;
}
}
接如下端口:
效果如下: