[DemoCode下载] Nano100 smartcard 当uart 使用 7bit通讯

[复制链接]
2357|8
 楼主| aboutjiming 发表于 2016-7-5 18:26 | 显示全部楼层 |阅读模式
当串口不够用的时候,客户可以使用smart card 接口当串口用。附件程序展示了smart card 当串口使用的7 bit 通讯方式。

Nano100sc7bit.rar

375.42 KB, 下载次数: 23

源程序

捉虫天师 发表于 2016-7-5 22:44 | 显示全部楼层
也可以通过IO口来模式,那么谁知道通过IO口模拟的时候是使用IO口的哪种状态,准双向模式还是普通的输入和输出?
 楼主| aboutjiming 发表于 2016-7-6 09:16 | 显示全部楼层
新唐的单片机I/O口只有推挽,准双向,开漏和高阻输入四种模式。用I/O口模拟串口可以用准双向,开漏都可以实现。新唐的硬件UART输出是推挽,输入是高阻输入模式。
gejigeji521 发表于 2016-7-29 21:24 | 显示全部楼层
通常不够用的时候大家习惯用IO来模拟串口,因为模拟比较简单
643757107 发表于 2016-7-29 23:20 | 显示全部楼层
没说怎么用,不知道怎么接线啊。
heisexingqisi 发表于 2016-7-30 13:02 | 显示全部楼层
通常是使用多于的IO口作为其他通讯接口的模拟接口。
598330983 发表于 2016-7-30 15:10 | 显示全部楼层
这个资料不是很多,有没有文字说明的
598330983 发表于 2016-7-30 15:10 | 显示全部楼层
  1. /******************************************************************************
  2. * [url=home.php?mod=space&uid=288409]@file[/url]     main.c
  3. * [url=home.php?mod=space&uid=895143]@version[/url]  V1.00
  4. * $Revision: 4 $
  5. * $Date: 14/09/11 7:15p $
  6. * [url=home.php?mod=space&uid=247401]@brief[/url]    Demonstrate Smartcard UART mode by connecting PA.8 and PA.9 pins.
  7. *
  8. * @note
  9. * Copyright (C) 2014 Nuvoton Technology Corp. All rights reserved.
  10. *****************************************************************************/
  11. #include <stdio.h>
  12. #include "Nano100Series.h"

  13. uint8_t au8TxBuf[] = "Hello World!";
  14. uint8_t au8RxBuf[13]={0,0,0,0,0,0,0,0,0,0,0,0,0};
  15. uint8_t        au8Rxindex=0;

  16. /**
  17.   * @brief  The interrupt services routine of smartcard port 0
  18.   * @param  None
  19.   * @retval None
  20.   */
  21. void SC0_IRQHandler(void)
  22. {
  23.     // Print SCUART received data to UART port
  24.     // Data length here is short, so we're not care about UART FIFO over flow.
  25.     UART_WRITE(UART0, SCUART_READ(SC0));

  26.     // RDA is the only interrupt enabled in this sample, this status bit
  27.     // automatically cleared after Rx FIFO empty. So no need to clear interrupt
  28.     // status here.

  29.     return;
  30. }

  31. void SC1_IRQHandler(void)
  32. {
  33.     UART_WRITE(UART0, SCUART_READ(SC0));

  34.                 au8RxBuf[au8Rxindex]=SCUART_READ(SC1);
  35.                 au8Rxindex++;
  36.                 if(au8Rxindex>=13)
  37.                 {
  38.                                 au8Rxindex=0;
  39.                 }
  40. }

  41. void SYS_Init(void)
  42. {
  43.     /*---------------------------------------------------------------------------------------------------------*/
  44.     /* Init System Clock                                                                                       */
  45.     /*---------------------------------------------------------------------------------------------------------*/
  46.     /* Unlock protected registers */
  47.     SYS_UnlockReg();

  48.     /* Enable External XTAL (4~24 MHz) */
  49.     CLK_EnableXtalRC(CLK_PWRCTL_HXT_EN_Msk);

  50.     /* Waiting for 12MHz clock ready */
  51.     CLK_WaitClockReady( CLK_CLKSTATUS_HXT_STB_Msk);

  52.     /* Switch HCLK clock source to HXT */
  53.     CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_HXT,CLK_HCLK_CLK_DIVIDER(1));

  54.     /* Enable IP clock */
  55.     CLK_EnableModuleClock(UART0_MODULE);
  56.     CLK_EnableModuleClock(SC0_MODULE);
  57.     CLK_EnableModuleClock(SC1_MODULE);

  58.     /* Select IP clock source */
  59.     CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UART_S_HXT, CLK_UART_CLK_DIVIDER(1));
  60.     CLK_SetModuleClock(SC0_MODULE, CLK_CLKSEL2_SC_S_HXT, CLK_SC0_CLK_DIVIDER(1));
  61.     CLK_SetModuleClock(SC1_MODULE, CLK_CLKSEL2_SC_S_HXT, CLK_SC0_CLK_DIVIDER(1));
  62.     /* Update System Core Clock */
  63.     /* User can use SystemCoreClockUpdate() to calculate SystemCoreClock. */
  64.     SystemCoreClockUpdate();


  65.     /*---------------------------------------------------------------------------------------------------------*/
  66.     /* Init I/O Multi-function                                                                                 */
  67.     /*---------------------------------------------------------------------------------------------------------*/
  68.     /* Set GPB multi-function pins for UART0 RXD and TXD */
  69.     SYS->PB_L_MFP &= ~(SYS_PB_L_MFP_PB0_MFP_Msk | SYS_PB_L_MFP_PB1_MFP_Msk);
  70.     SYS->PB_L_MFP |= (SYS_PB_L_MFP_PB1_MFP_UART0_TX | SYS_PB_L_MFP_PB0_MFP_UART0_RX);
  71.     /* Set PA.8 and PA.9 pin for SC UART mode */
  72.     SYS->PA_H_MFP &= ~(SYS_PA_H_MFP_PA8_MFP_Msk | SYS_PA_H_MFP_PA9_MFP_Msk);
  73.     SYS->PA_H_MFP |= (SYS_PA_H_MFP_PA8_MFP_SC0_CLK | SYS_PA_H_MFP_PA9_MFP_SC0_DAT);
  74.                 SYS->PC_L_MFP &= ~(SYS_PC_L_MFP_PC0_MFP_Msk | SYS_PC_L_MFP_PC1_MFP_Msk);
  75.     SYS->PC_L_MFP |= (SYS_PC_L_MFP_PC0_MFP_SC1_CLK | SYS_PC_L_MFP_PC1_MFP_SC1_DAT);
  76.     /* Lock protected registers */
  77.     SYS_LockReg();
  78. }

  79. int main(void)
  80. {
  81.     /* Init System, IP clock and multi-function I/O
  82.        In the end of SYS_Init() will issue SYS_LockReg()
  83.        to lock protected register. If user want to write
  84.        protected register, please issue SYS_UnlockReg()
  85.        to unlock protected register if necessary */
  86.     SYS_Init();

  87.     /* Init UART to 115200-8n1 for print message */
  88.     UART_Open(UART0, 115200);

  89.     printf("This sample code demos smartcard interface UART mode\n");
  90.     printf("Please connect SC0 CLK pin(PA.8) with SC0 I/O pin(PA.9)\n");
  91.     printf("Hit any key to continue\n");
  92. //     getchar();

  93.     // Open smartcard interface 0 in UART mode.
  94.     SCUART_Open(SC0, 115200);
  95.           SCUART_Open(SC1, 115200);
  96.     // Enable smartcard receive interrupt
  97.     SCUART_ENABLE_INT(SC0, SC_IER_RDA_IE_Msk);
  98.     NVIC_EnableIRQ(SC0_IRQn);
  99.     SCUART_ENABLE_INT(SC1, SC_IER_RDA_IE_Msk);
  100.     NVIC_EnableIRQ(SC1_IRQn);
  101.     // Write output buffer to smartcard tx FIFO
  102.     SCUART_Write(SC0, au8TxBuf, sizeof(au8TxBuf));



  103.     while(1);
  104. }

  105. /*** (C) COPYRIGHT 2014 Nuvoton Technology Corp. ***/



mintspring 发表于 2016-7-30 16:00 | 显示全部楼层
// Open smartcard interface 0 in UART mode.
    SCUART_Open(SC0, 115200);
          SCUART_Open(SC1, 115200);
    // Enable smartcard receive interrupt
    SCUART_ENABLE_INT(SC0, SC_IER_RDA_IE_Msk);
    NVIC_EnableIRQ(SC0_IRQn);
    SCUART_ENABLE_INT(SC1, SC_IER_RDA_IE_Msk);
    NVIC_EnableIRQ(SC1_IRQn);
    // Write output buffer to smartcard tx FIFO
    SCUART_Write(SC0, au8TxBuf, sizeof(au8TxBuf));
这些是主要
您需要登录后才可以回帖 登录 | 注册

本版积分规则

2

主题

6

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部