오늘 또 식겁? 했다.

분명이 두달전에 파생된 펌웨어는 통신이 잘 되는데!!!

원본 펌웨어는 쓰레기 값이 자꾸만 수신된다.

PC에서 송신하면 STM32에서 계속 다른 응답이 전방에 섞여서 왔다.

 

왜! 왜!

 

결국 파생된 소스와 원본을 면밀히 검토한 결과 상수 RESET 의 문제였다.

종종 아래의 코드처럼 KEY 값을 정의한다.  

9번 값이 보이시는가?

특정 조합을 누르면 SoftReset을 하려고 만든게 화근!

 

#define UP      1
#define DOWN    2
#define LEFT    3
#define RIGHT   4
#define ENTER   5
#define CANCEL  6
#define RESET   9

#define ON 1
#define OFF 0

 

9번으로 인하 아래 코드에 영향을 받았다.

따라서 수신 인터럽트를 처리하러 왔다가.

송신까지 건들게 되는게 원인이었다.


void USART2_IRQHandler(void)  // RS232
{
  if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)
  {
    /* Read one byte from the receive data register */
    USART_ClearITPendingBit(USART2, USART_IT_RXNE);
    RxBuffer2[RxHead2++] = USART_ReceiveData(USART2);   
    if(RxHead2 == MAX_RX2_BUFFER_SIZE) RxHead2 = 0;
  }
  
  if(USART_GetITStatus(USART2, USART_IT_TXE) != RESET)
  {  
    /* Write one byte to the transmit data register */
    USART_SendData(USART2, TxBuffer2[TxTail2++]);
   
    if(TxTail2 == MAX_TX2_BUFFER_SIZE) TxTail2 = 0;
   
    if(TxTail2 == TxHead2)
    {
      /* Disable the USARTz Transmit interrupt */
      USART_ITConfig(USART2, USART_IT_TXE, DISABLE);
    }
  }
}

 

 

다음에는 같은 실수 반복하지 말자!

Posted by +깡통+
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ReadOnlyClass
{
    class ReadOnlyClass
    {
        public int x;
        public readonly int y = 1;
        public readonly int z;

        public ReadOnlyClass()
        {
            z = 24;
        }

        public ReadOnlyClass(int x, int y, int z)
        {
            this.x = x;
            this.y = y;
            this.z = z;
        }

    }

    class Program
    {
        static void Main(string[] args)
        {
            ReadOnlyClass o1 = new ReadOnlyClass(1, 2, 3);
            Console.WriteLine("o1: x={0}, y={1}, z={2}", o1.x, o1.y, o1.z);

            ReadOnlyClass o2 = new ReadOnlyClass();
            Console.WriteLine("o2: x={0}, y={1}, z={2}", o2.x, o2.y, o2.z);

            o2.x = 5;
            o2.y = 6;
            o2.z = 7;
        }
    }
}


39~40번 라인에 문제가 있다고 컴파일 하지 않아도 친절하게 알려준다. 기특 기특. ^^


Posted by +깡통+
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ParseTest
{
    class ParseTest
    {
        enum Colors { Red = 1, Green = 2, Blue = 4, Yellow = 8 };
        static void Main(string[] args)
        {
            Console.WriteLine("컬러 열거형에는 이런 값들이 있다 :");
            foreach (string s in Enum.GetNames(typeof(Colors)))
                Console.WriteLine(s);
            Console.WriteLine();
            Colors myOrange = (Colors)Enum.Parse(typeof(Colors), "Red, Yellow");
            Console.WriteLine("오랜지색 값은 합쳐진 것이다. {0}", myOrange);
        }
    }
}

Parse 메소드는 하나 이상의 열거된 상수의 이름이나 숫자 값의 문자열 표현을 해당하는 열거된 상수로 변환한다.

즉.. 숫자를 지정하지 않았으면 문자가 튀어 나온다.

이것 참 편리한 도구다.

다른 사이트도 있을듯 한데. ㅎㅎㅎ

http://hilite.me/


Posted by +깡통+