RL78/G13 CSIのマスタ連続送受信でオーバーランエラーが発生する

こんにちは、ユキと申します。

RL78/G13のCSIで、バッファ空き割込みを使った連続送受信をマスタとして行うときのことについて
ご教授いただけないでしょうか。
コンパイラはCC-RL、IDEはe2studioを使用しております。

現在、コード生成を使い、CSI21を以下のような設定で動作させようとしています。

転送モード:連続転送モード
データ長:8ビット
データ転送方向:MSB
データ送受信タイミング:タイプ4
転送レート:
 クロック・モード:内部クロック(マスタ)
 ボー・レート:2000000bps
通信完了割り込み優先順位:低
コールバック機能設定:すべて有効

コード生成を実行した上で、自分のコードでR_CSI21_Send_Receive()を呼び出しているのですが、
以下のような現象が起きています。

・1バイトのデータを送信した時は通信が成功する
・2バイト以上のデータを送信するとオーバーランエラーが発生する
・シングル転送モードを使った場合は、2バイト以上のデータを送信してもオーバーランエラーは発生しない

そして、r_cg_serial_user.cのr_csi21_interrupt()の、

if (g_csi21_tx_count > 0U)
{
    if (g_csi21_tx_count != (g_csi21_send_length - 1U))
    {
        *gp_csi21_rx_address = SIO21;
        gp_csi21_rx_address++;
    }

    SIO21 = *gp_csi21_tx_address;
    gp_csi21_tx_address++;
    g_csi21_tx_count--;
}

上記のコードを以下のように書き換えてみると、オーバーランエラーが発生しなくなりました。

if (g_csi21_tx_count > 0U) 
{

    *gp_csi21_rx_address = SIO21;
    gp_csi21_rx_address++;

    SIO21 = *gp_csi21_tx_address;
    gp_csi21_tx_address++;
    g_csi21_tx_count--;
}

期待通りの動作をするようになったものの、何故こうなるのか理解できておりません。
上記はコード生成でできるコードなので、私の使い方が間違っている気がするのですが……

バッファオーバーランが起きる時、送信データの1バイト目を書き込んだ後の最初のバッファ空き割込みで、
実際にはSDRにデータが存在するような動作をしているように見えます。

しかし、ハードウェアマニュアルを読むと、
送信データの1バイト目を書き込んだ後の最初のバッファ空き割込みでは、
データを受信していないし、バッファ空き割込みなのだからSDRは空いている。
何もせずに2バイト目のデータをSDRに書き込んで良い
というように読み取れました。

私の理解は正しいのでしょうか。そして、何故このような動作をするのでしょうか。
ご助言をいただけると嬉しいです。

足りない情報がございましたら、おっしゃってください。

よろしくお願いいたします。

Parents
  • ユキさん、チョコさん、こんにちは。NoMaYです。

    Renesas RL78 SimulatorのTrace機能で調べてみました。以下のことのようです。

    (0) トレース開始時刻を便宜上 -0.125μs とします
    (1) 送信関数内で送信データレジスタに最初に書いた時刻は 0μs
    (2) 最初の割り込みへ飛んだ時の時刻が 2.375μs → この時点では受信完了していない
    (3) 最初の割り込みで送信データレジスタに書いた時刻が 7.375μs → この時点では受信完了している
    ⇒ コード生成したコードは最初の割り込みでは受信データレジスタを読まないのでオーバーランする
    ⇒ 別の見方をすると、CPUクロックが倍以上か、ボーレートが半分以下か、どちらかならオーバーランしない筈

    [追記] なお、上記はデフォルト最適化の場合ですが、デバッグ優先(最適化無し)では以下の通りでした。

    (1') 送信関数内で送信データレジスタに最初に書いた時刻は 0μs (ただしトレース開始時刻は上記とは若干異なります)
    (2') 最初の割り込みへ飛んだ時の時刻が 2.625μs
    (3') 最初の割り込みで送信データレジスタに書いた時刻が 7.750μs

    以下、トレースデータの画面コピーです。

    トレース開始時刻を便宜上 -0.125μs として、送信関数内で送信データレジスタに最初に書いた時刻を 0μs とします


    最初の割り込みへ飛んだ時の時刻が 2.375μs


    最初の割り込みで送信データレジスタに書いた時刻が 7.375μs


    [追記] 送信関数内で送信データレジスタに最初に書いてから最初の割り込みへ飛ぶまで(R/W/VECTの時刻が少々雑かな)


    以下、関連情報です。

    RL78/G13 ユーザーズマニュアル ハードウェア編
    www.renesas.com/jp/ja/search/keyword-search.html#genre=document&q=RL78/G13+ハードウェア編



    手元のCS+ V8.01+CC-RL V1.02+デフォルト最適化での今回の割り込み処理のソースのリストファイルの抜粋

    DefaultBuild/r_cg_serial_user.prn

    0245.sim_rl78g13_csi_overrun_prnfile_20191010.txt
    00000000                      104  	;***       68 : static void __near r_csi11_interrupt(void)
    00000000                      105  	.LINE "C:/Renesas/RL78/issue_20191009/csp_projects/RL78G13/src/r_cg_serial_user.c", 68
    00000000 C1                   106  	push ax
    00000001 C3                   107  	push bc
    00000002 C5                   108  	push de
    00000003 C7                   109  	push hl
    00000004 8EFD                 110  	mov a, es
    00000006 70                   111  	mov x, a
    00000007 8EFC                 112  	mov a, cs
    00000009 C1                   113  	push ax
    0000000A C7                   114  	push hl
    0000000B                      115  	;***       69 : {
    0000000B                      116  	;***       70 :     volatile uint8_t err_type;
    0000000B                      117  	;***       71 : 
    0000000B                      118  	;***       72 :     err_type = (uint8_t)(SSR03 & _0001_SAU_OVERRUN_ERROR);
    0000000B                      119  	.LINE "C:/Renesas/RL78/issue_20191009/csp_projects/RL78G13/src/r_cg_serial_user.c", 72
    0000000B AF0601               120  	movw ax, !0x0106
    0000000E 60                   121  	mov a, x
    0000000F 5C01                 122  	and a, #0x01
    00000011 9800                 123  	mov [sp+0x00], a
    00000013                      124  	;***       73 :     SIR03 = (uint16_t)err_type;
    00000013                      125  	.LINE "C:/Renesas/RL78/issue_20191009/csp_projects/RL78G13/src/r_cg_serial_user.c", 73
    00000013 8800                 126  	mov a, [sp+0x00]
    00000015 318E                 127  	shrw ax, 8+0x00000
    00000017 BF0E01               128  	movw !0x010E, ax
    0000001A                      129  	;***       74 : 
    0000001A                      130  	;***       75 :     if (1U == err_type)
    0000001A                      131  	.LINE "C:/Renesas/RL78/issue_20191009/csp_projects/RL78G13/src/r_cg_serial_user.c", 75
    0000001A 8800                 132  	mov a, [sp+0x00]
    0000001C 91                   133  	dec a
    0000001D DF00                 134  	bnz $.BB@LABEL@1_2
    0000001F                      135  .BB@LABEL@1_1:	; if_then_bb
    0000001F                      136  	;***       76 :     {
    0000001F                      137  	;***       77 :         r_csi11_callback_error(err_type);    /* overrun error occurs */
    0000001F                      138  	.LINE "C:/Renesas/RL78/issue_20191009/csp_projects/RL78G13/src/r_cg_serial_user.c", 77
    0000001F 8800                 139  	mov a, [sp+0x00]
    00000021 FC000000             140  	call !!_r_csi11_callback_error@1
    00000025 EF00                 141  	br $.BB@LABEL@1_8
    00000027                      142  .BB@LABEL@1_2:	; if_else_bb
    00000027                      143  	;***       78 :     }
    00000027                      144  	;***       79 :     else
    00000027                      145  	;***       80 :     {
    00000027                      146  	;***       81 :         if (g_csi11_tx_count > 0U) 
    00000027                      147  	.LINE "C:/Renesas/RL78/issue_20191009/csp_projects/RL78G13/src/r_cg_serial_user.c", 81
    00000027 AF0000               148  	movw ax, !LOWW(_g_csi11_tx_count)
    0000002A 6168                 149  	or a, x
    0000002C DF00                 150  	bnz $.BB@LABEL@1_9
    0000002E                      151  .BB@LABEL@1_3:	; if_else_bb34
    0000002E                      152  	;***       82 :         {
    0000002E                      153  	;***       83 :             if (g_csi11_tx_count != (g_csi11_send_length - 1U)) 
    0000002E                      154  	;***       84 :             {
    0000002E                      155  	;***       85 :                 *gp_csi11_rx_address = SIO11;
    0000002E                      156  	;***       86 :                 gp_csi11_rx_address++;
    0000002E                      157  	;***       87 :             }
    0000002E                      158  	;***       88 :             
    0000002E                      159  	;***       89 :             SIO11 = *gp_csi11_tx_address;
    0000002E                      160  	;***       90 :             gp_csi11_tx_address++;
    0000002E                      161  	;***       91 :             g_csi11_tx_count--;
    0000002E                      162  	;***       92 :         }
    0000002E                      163  	;***       93 :         else 
    0000002E                      164  	;***       94 :         {
    0000002E                      165  	;***       95 :             if ((SMR03 & _0001_SAU_BUFFER_EMPTY) == 1U) 
    0000002E                      166  	.LINE "C:/Renesas/RL78/issue_20191009/csp_projects/RL78G13/src/r_cg_serial_user.c", 95
    0000002E AF1601               167  	movw ax, !0x0116
    00000031 60                   168  	mov a, x
    00000032 310300               169  	bt a.0, $.BB@LABEL@1_5
    00000035                      170  .BB@LABEL@1_4:	; if_else_bb58
    00000035                      171  	;***       96 :             {
    00000035                      172  	;***       97 :                 r_csi11_callback_sendend();    /* complete send */
    00000035                      173  	;***       98 :                 *gp_csi11_rx_address = SIO11;
    00000035                      174  	;***       99 :                 gp_csi11_rx_address++;    
    00000035                      175  	;***      100 :                 
    00000035                      176  	;***      101 :                 if ((SSR03 & _0040_SAU_UNDER_EXECUTE) == 0U)
    00000035                      177  	;***      102 :                 {
    00000035                      178  	;***      103 :                     *gp_csi11_rx_address = SIO11;
    00000035                      179  	;***      104 :                     r_csi11_callback_receiveend();    /* complete receive */
    00000035                      180  	;***      105 :                 }
    00000035                      181  	;***      106 :                 else
    00000035                      182  	;***      107 :                 {
    00000035                      183  	;***      108 :                     SMR03 &= ~_0001_SAU_BUFFER_EMPTY;
    00000035                      184  	;***      109 :                 }
    00000035                      185  	;***      110 :             }
    00000035                      186  	;***      111 :             else 
    00000035                      187  	;***      112 :             {
    00000035                      188  	;***      113 :                 *gp_csi11_rx_address = SIO11;
    00000035                      189  	.LINE "C:/Renesas/RL78/issue_20191009/csp_projects/RL78G13/src/r_cg_serial_user.c", 113
    00000035 EB0000               190  	movw de, !LOWW(_gp_csi11_rx_address)
    00000038 EF00                 191  	br $.BB@LABEL@1_6
    0000003A                      192  .BB@LABEL@1_5:	; if_then_bb40
    0000003A                      193  	.LINE "C:/Renesas/RL78/issue_20191009/csp_projects/RL78G13/src/r_cg_serial_user.c", 97
    0000003A FC000000             194  	call !!_r_csi11_callback_sendend@1
    0000003E                      195  	.LINE "C:/Renesas/RL78/issue_20191009/csp_projects/RL78G13/src/r_cg_serial_user.c", 98
    0000003E EB0000               196  	movw de, !LOWW(_gp_csi11_rx_address)
    00000041 8E46                 197  	mov a, 0xFFF46
    00000043 99                   198  	mov [de], a
    00000044                      199  	.LINE "C:/Renesas/RL78/issue_20191009/csp_projects/RL78G13/src/r_cg_serial_user.c", 99
    00000044 AF0000               200  	movw ax, !LOWW(_gp_csi11_rx_address)
    00000047 A1                   201  	incw ax
    00000048 14                   202  	movw de, ax
    00000049 BF0000               203  	movw !LOWW(_gp_csi11_rx_address), ax
    0000004C                      204  	.LINE "C:/Renesas/RL78/issue_20191009/csp_projects/RL78G13/src/r_cg_serial_user.c", 101
    0000004C AF0601               205  	movw ax, !0x0106
    0000004F 60                   206  	mov a, x
    00000050 316300               207  	bt a.6, $.BB@LABEL@1_7
    00000053                      208  .BB@LABEL@1_6:	; if_then_bb51
    00000053                      209  	.LINE "C:/Renesas/RL78/issue_20191009/csp_projects/RL78G13/src/r_cg_serial_user.c", 0
    00000053 8E46                 210  	mov a, 0xFFF46
    00000055 99                   211  	mov [de], a
    00000056 FC000000             212  	call !!_r_csi11_callback_receiveend@1
    0000005A EF00                 213  	br $.BB@LABEL@1_8
    0000005C                      214  .BB@LABEL@1_7:	; if_else_bb54
    0000005C 341601               215  	movw de, #0x0116
    0000005F                      216  	.LINE "C:/Renesas/RL78/issue_20191009/csp_projects/RL78G13/src/r_cg_serial_user.c", 108
    0000005F A9                   217  	movw ax, [de]
    00000060 08                   218  	xch a, x
    00000061 5CFE                 219  	and a, #0xFE
    00000063 08                   220  	xch a, x
    00000064 B9                   221  	movw [de], ax
    00000065                      222  .BB@LABEL@1_8:	; if_else_bb54
    00000065                      223  	.LINE "C:/Renesas/RL78/issue_20191009/csp_projects/RL78G13/src/r_cg_serial_user.c", 0
    00000065 C6                   224  	pop hl
    00000066 C0                   225  	pop ax
    00000067 9EFC                 226  	mov cs, a
    00000069 60                   227  	mov a, x
    0000006A 9EFD                 228  	mov es, a
    0000006C C6                   229  	pop hl
    0000006D C4                   230  	pop de
    0000006E C2                   231  	pop bc
    0000006F C0                   232  	pop ax
    00000070                      233  	.LINE "C:/Renesas/RL78/issue_20191009/csp_projects/RL78G13/src/r_cg_serial_user.c", 118
    00000070 61FC                 234  	reti
    00000072                      235  .BB@LABEL@1_9:	; if_then_bb15
    00000072                      236  	.LINE "C:/Renesas/RL78/issue_20191009/csp_projects/RL78G13/src/r_cg_serial_user.c", 83
    00000072 DB0000               237  	movw bc, !LOWW(_g_csi11_tx_count)
    00000075 F6                   238  	clrw ax
    00000076 B1                   239  	decw ax
    00000077 020000               240  	addw ax, !LOWW(_g_csi11_send_length)
    0000007A 43                   241  	cmpw ax, bc
    0000007B DD00                 242  	bz $.BB@LABEL@1_11
    0000007D                      243  .BB@LABEL@1_10:	; if_then_bb22
    0000007D                      244  	.LINE "C:/Renesas/RL78/issue_20191009/csp_projects/RL78G13/src/r_cg_serial_user.c", 85
    0000007D EB0000               245  	movw de, !LOWW(_gp_csi11_rx_address)
    00000080 8E46                 246  	mov a, 0xFFF46
    00000082 99                   247  	mov [de], a
    00000083                      248  	.LINE "C:/Renesas/RL78/issue_20191009/csp_projects/RL78G13/src/r_cg_serial_user.c", 86
    00000083 A20000               249  	incw !LOWW(_gp_csi11_rx_address)
    00000086                      250  .BB@LABEL@1_11:	; if_break_bb
    00000086                      251  	.LINE "C:/Renesas/RL78/issue_20191009/csp_projects/RL78G13/src/r_cg_serial_user.c", 89
    00000086 EB0000               252  	movw de, !LOWW(_gp_csi11_tx_address)
    00000089 89                   253  	mov a, [de]
    0000008A 9E46                 254  	mov 0xFFF46, a ← ★★★★送信データレジスタへの書き込み★★★★
    0000008C                      255  	.LINE "C:/Renesas/RL78/issue_20191009/csp_projects/RL78G13/src/r_cg_serial_user.c", 90
    0000008C A5                   256  	incw de
    0000008D 15                   257  	movw ax, de
    0000008E BF0000               258  	movw !LOWW(_gp_csi11_tx_address), ax
    00000091                      259  	.LINE "C:/Renesas/RL78/issue_20191009/csp_projects/RL78G13/src/r_cg_serial_user.c", 91
    00000091 B20000               260  	decw !LOWW(_g_csi11_tx_count)
    00000094 EF00                 261  	br $.BB@LABEL@1_8
    00000000                      262  	.SECTION .textf,TEXTF
    00000000                      263  _r_csi11_callback_receiveend@1:
    00000000                      264  	.STACK _r_csi11_callback_receiveend@1 = 4
    00000000                      265  	;***      114 :                 r_csi11_callback_receiveend();    /* complete receive */
    00000000                      266  	;***      115 :             }
    00000000                      267  	;***      116 :         }
    00000000                      268  	;***      117 :     }
    00000000                      269  	;***      118 : }
    


    トレースデータの最初の部分と割り込み処理の部分の抜粋
    5460.sim_rl78g13_csi_overrun_trcdata_20191010.txt
    番号   時間                          行番号/アドレス      ソース/逆アセンブル                                         アドレス      データ        
    --------------------------------------------------------------------------------------------------------------------------------------------------
                                                              _R_CSI11_Send_Receive:                                                                  
    0                                    r_cg_serial.c#167            SIO11 = *gp_csi11_tx_address;    /* started by writing data to SDR[7:0] */      
    0      00h00min00s000ms000µs000ns    0x00304              +52         MOV   A,[DE]                                                                
    3                                                                                                                     0xffe12       R 0           
    5                                    r_cg_serial.c#167            SIO11 = *gp_csi11_tx_address;    /* started by writing data to SDR[7:0] */ <<<RXD1=0>>>
    5      00h00min00s000ms000µs125ns    0x00305              +53         MOV   RXD1,A                                                                
    8      00h00min00s000ms000µs125ns                                                                                     RXD1          W 0           
    途中省略
                                                              _r_csi11_interrupt@1:                                                                   
    47                                   r_cg_serial_user.c#68        static void __near r_csi11_interrupt(void)                                      
    47     00h00min00s000ms002µs500ns    0x0012b              +0          PUSH  AX                                                                    
    50     00h00min00s000ms002µs500ns                                                                                     0xffe06       W 0           
    51     00h00min00s000ms002µs500ns                                                                                     0xffe07       W 0           
    52                                   r_cg_serial_user.c#68        static void __near r_csi11_interrupt(void)                                      
    52     00h00min00s000ms002µs625ns    0x0012c              +1          PUSH  BC                                                                    
    55     00h00min00s000ms002µs625ns                                                                                     0xffe04       W 5           
    56     00h00min00s000ms002µs625ns                                                                                     0xffe05       W 0           
    57                                   r_cg_serial_user.c#68        static void __near r_csi11_interrupt(void)                                      
    57     00h00min00s000ms002µs750ns    0x0012d              +2          PUSH  DE                                                                    
    60     00h00min00s000ms002µs750ns                                                                                     0xffe02       W 19          
    61     00h00min00s000ms002µs750ns                                                                                     0xffe03       W 254         
    62                                   r_cg_serial_user.c#68        static void __near r_csi11_interrupt(void)                                      
    62     00h00min00s000ms002µs875ns    0x0012e              +3          PUSH  HL                                                                    
    65     00h00min00s000ms002µs875ns                                                                                     0xffe00       W 32          
    66     00h00min00s000ms002µs875ns                                                                                     0xffe01       W 254         
    67                                   r_cg_serial_user.c#68        static void __near r_csi11_interrupt(void)                                      
    67     00h00min00s000ms003µs000ns    0x0012f              +4          MOV   A,ES                                                                  
    69     00h00min00s000ms003µs000ns                                                                                     0xffffd       R 0           
    71                                   r_cg_serial_user.c#68        static void __near r_csi11_interrupt(void)                                      
    71     00h00min00s000ms003µs125ns    0x00131              +6          MOV   X,A                                                                   
    74                                   r_cg_serial_user.c#68        static void __near r_csi11_interrupt(void)                                      
    74     00h00min00s000ms003µs250ns    0x00132              +7          MOV   A,CS                                                                  
    76     00h00min00s000ms003µs250ns                                                                                     0xffffc       R 0           
    78                                   r_cg_serial_user.c#68        static void __near r_csi11_interrupt(void)                                      
    78     00h00min00s000ms003µs375ns    0x00134              +9          PUSH  AX                                                                    
    81     00h00min00s000ms003µs375ns                                                                                     0xffdfe       W 0           
    82     00h00min00s000ms003µs375ns                                                                                     0xffdff       W 0           
    83                                   r_cg_serial_user.c#68        static void __near r_csi11_interrupt(void)                                      
    83     00h00min00s000ms003µs500ns    0x00135              +10         PUSH  HL                                                                    
    86     00h00min00s000ms003µs500ns                                                                                     0xffdfc       W 32          
    87     00h00min00s000ms003µs500ns                                                                                     0xffdfd       W 254         
    88                                   r_cg_serial_user.c#72        err_type = (uint8_t)(SSR03 & _0001_SAU_OVERRUN_ERROR); <<<SSR03=64>>>           
    88     00h00min00s000ms003µs625ns    0x00136              +11         MOVW  AX,!SSR03                                                             
    91     00h00min00s000ms003µs625ns                                                                                     SSR03L        R 64          
    92     00h00min00s000ms003µs625ns                                                                                     0xf0107       R 0           
    95                                   r_cg_serial_user.c#72        err_type = (uint8_t)(SSR03 & _0001_SAU_OVERRUN_ERROR);                          
    95     00h00min00s000ms003µs750ns    0x00139              +14         MOV   A,X                                                                   
    98                                   r_cg_serial_user.c#72        err_type = (uint8_t)(SSR03 & _0001_SAU_OVERRUN_ERROR);                          
    98     00h00min00s000ms003µs875ns    0x0013a              +15         AND   A,#1H                                                                 
    102                                  r_cg_serial_user.c#72        err_type = (uint8_t)(SSR03 & _0001_SAU_OVERRUN_ERROR);                          
    102    00h00min00s000ms004µs000ns    0x0013c              +17         MOV   [SP+0H],A                                                             
    105    00h00min00s000ms004µs000ns                                                                                     0xffff8       R 252         
    106    00h00min00s000ms004µs000ns                                                                                     0xffff9       R 253         
    107    00h00min00s000ms004µs000ns                                                                                     0xffdfc       W 0           
    108                                  r_cg_serial_user.c#73        SIR03 = (uint16_t)err_type;                                                     
    108    00h00min00s000ms004µs125ns    0x0013e              +19         MOV   A,[SP+0H]                                                             
    110    00h00min00s000ms004µs125ns                                                                                     0xffff8       R 252         
    111    00h00min00s000ms004µs125ns                                                                                     0xffff9       R 253         
    112    00h00min00s000ms004µs125ns                                                                                     0xffdfc       R 0           
    114                                  r_cg_serial_user.c#73        SIR03 = (uint16_t)err_type;                                                     
    114    00h00min00s000ms004µs250ns    0x00140              +21         SHRW  AX,8H                                                                 
    120                                  r_cg_serial_user.c#73        SIR03 = (uint16_t)err_type; <<<SIR03=0>>>                                       
    120    00h00min00s000ms004µs375ns    0x00142              +23         MOVW  !SIR03,AX                                                             
    125    00h00min00s000ms004µs375ns                                                                                     SIR03L        W 0           
    126    00h00min00s000ms004µs375ns                                                                                     0xf010f       W 0           
    127                                  r_cg_serial_user.c#75        if (1U == err_type)                                                             
    127    00h00min00s000ms004µs500ns    0x00145              +26         MOV   A,[SP+0H]                                                             
    129    00h00min00s000ms004µs500ns                                                                                     0xffff8       R 252         
    130    00h00min00s000ms004µs500ns                                                                                     0xffff9       R 253         
    131    00h00min00s000ms004µs500ns                                                                                     0xffdfc       R 0           
    133                                  r_cg_serial_user.c#75        if (1U == err_type)                                                             
    133    00h00min00s000ms004µs625ns    0x00147              +28         DEC   A                                                                     
    136                                  r_cg_serial_user.c#75        if (1U == err_type)                                                             
    136    00h00min00s000ms004µs750ns    0x00148              +29         BNZ   $_r_csi11_interrupt@1+0x27                                            
    138                                  r_cg_serial_user.c#81        if (g_csi11_tx_count > 0U) <<<g_csi11_tx_count=4>>>                             
    138    00h00min00s000ms005µs250ns    0x00152              +39         MOVW  AX,!_g_csi11_tx_count                                                 
    141    00h00min00s000ms005µs250ns                                                                                     0xfcf0a       R 4           
    142    00h00min00s000ms005µs250ns                                                                                     0xfcf0b       R 0           
    145                                  r_cg_serial_user.c#81        if (g_csi11_tx_count > 0U)                                                      
    145    00h00min00s000ms005µs375ns    0x00155              +42         OR    A,X                                                                   
    150                                  r_cg_serial_user.c#81        if (g_csi11_tx_count > 0U)                                                      
    150    00h00min00s000ms005µs500ns    0x00157              +44         BNZ   $_r_csi11_interrupt@1+0x72                                            
    152                                  r_cg_serial_user.c#83        if (g_csi11_tx_count != (g_csi11_send_length - 1U)) <<<g_csi11_tx_count=4>>>    
    152    00h00min00s000ms006µs000ns    0x0019d              +114        MOVW  BC,!_g_csi11_tx_count                                                 
    155    00h00min00s000ms006µs000ns                                                                                     0xfcf0a       R 4           
    156    00h00min00s000ms006µs000ns                                                                                     0xfcf0b       R 0           
    159                                  r_cg_serial_user.c#83        if (g_csi11_tx_count != (g_csi11_send_length - 1U))                             
    159    00h00min00s000ms006µs125ns    0x001a0              +117        CLRW  AX                                                                    
    162                                  r_cg_serial_user.c#83        if (g_csi11_tx_count != (g_csi11_send_length - 1U))                             
    162    00h00min00s000ms006µs250ns    0x001a1              +118        DECW  AX                                                                    
    167                                  r_cg_serial_user.c#83        if (g_csi11_tx_count != (g_csi11_send_length - 1U)) <<<g_csi11_send_length=5>>> 
    167    00h00min00s000ms006µs375ns    0x001a2              +119        ADDW  AX,!_g_csi11_send_length                                              
    172    00h00min00s000ms006µs375ns                                                                                     0xfcf08       R 5           
    173    00h00min00s000ms006µs375ns                                                                                     0xfcf09       R 0           
    176                                  r_cg_serial_user.c#83        if (g_csi11_tx_count != (g_csi11_send_length - 1U))                             
    176    00h00min00s000ms006µs500ns    0x001a5              +122        CMPW  AX,BC                                                                 
    181                                  r_cg_serial_user.c#83        if (g_csi11_tx_count != (g_csi11_send_length - 1U))                             
    181    00h00min00s000ms006µs625ns    0x001a6              +123        BZ    $_r_csi11_interrupt@1+0x86                                            
    183                                  r_cg_serial_user.c#89        SIO11 = *gp_csi11_tx_address; <<<gp_csi11_tx_address=65043>>>                   
    183    00h00min00s000ms007µs125ns    0x001b1              +134        MOVW  DE,!_gp_csi11_tx_address                                              
    186    00h00min00s000ms007µs125ns                                                                                     0xfcf06       R 19          
    187    00h00min00s000ms007µs125ns                                                                                     0xfcf07       R 254         
    190                                  r_cg_serial_user.c#89        SIO11 = *gp_csi11_tx_address;                                                   
    190    00h00min00s000ms007µs250ns    0x001b4              +137        MOV   A,[DE]                                                                
    193    00h00min00s000ms007µs250ns                                                                                     0xffe13       R 1           
    195                                  r_cg_serial_user.c#89        SIO11 = *gp_csi11_tx_address; <<<RXD1=1>>>                                      
    195    00h00min00s000ms007µs500ns    0x001b5              +138        MOV   RXD1,A                                                                
    198    00h00min00s000ms007µs500ns                                                                                     RXD1          W 1 ← ★★★★送信データレジスタへの書き込み★★★★
    以後省略
    


    [追記]

    これって、CPUクロックとボーレートの関係が妥当でも、最初の割り込み発生時に重たい割り込み処理が行われていて、最初の割り込み受付がもしデッドラインを超えて遅れたら、普通に誤動作してしまうような、、、

    [追記その2]

    最初の割り込みは、メイン側で割り込みを許可した途端に発生するから、大丈夫なのかな、、、

    [追記その3]

    待てよ、待てよ、待てよ、そのメイン側での割り込みを許可するタイミングが、重たい割り込み処理のせいで遅れたら、やはり駄目な気がする、、、

    これは、制限事項文書とかも見て、後でちゃんと投稿することにします。グダグダと追記して、すみません。

  • チョコさん、NoMaYさん
    お世話になっております。

    NoMaYさんがシミュレータで確認してくださったのが、
    まさに私が考えていた状況です!ありがとうございます。
    シミュレータでも同じような結果になったということで安心しました。
    というか、シミュレータでここまで確認できるのですね……元の記事も読んでみます。

    CSIのボーレートを落とすか、DMAを使うかしようと考え始めたところです。
    DMAは使ったことがないので、まずはユーザーマニュアルとサンプルコードを読んだのですが、
    DMAでは連続送信または連続受信のどちらかはできても、
    連続送受信(連続送信と同時に受信したデータを得る)はできない気がしました。
    この考え方は正しいでしょうか?

    一応、NoMaYさんが添付してくださったソースコードは修正してアップさせていただきますね。
    お待ちください。
  • チョコさん、NoMaYさん

    現象が起きる状態のソースコードを添付しました。

    7840.issue_20191010.zip

Reply Children
  • 取り急ぎ状況だけコメントします。
    仕事の方では、今回はそこまで速度にシビアになる必要がないということで、
    バッファ空き割り込みではなく送受信完了割り込みを使ったシングル転送モードで進めることにしました。
    シングル転送モードでは既に動作確認が取れていましたので。

    解決を急ぐ必要はなくなりましたが、この現象については気になるので、
    この後もゆっくりお話させていただければ嬉しいです。