Skip to content

Instantly share code, notes, and snippets.

@indra1234
Last active June 12, 2022 20:02
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save indra1234/793d38c08da32e088e57 to your computer and use it in GitHub Desktop.
Save indra1234/793d38c08da32e088e57 to your computer and use it in GitHub Desktop.
How to make my projects MISRA-C compatible

How to Checking MISRA-C (2004) rule of your programming code.

  1. MISRA_C testing is very important for checking your programming warning means we follow some rules to solve the warning problem. When we are write a program in C software or Keil IDE or Mikroelectronica IDE then we show after build the project the result should be shown: your program(xx.c) is compile successfully with 0 error and 100 or more errors. So, that is the one default in program because sometimes it happens your programming have a no error but with warnings when you burn this code in your microcontroller chip then In here MISRA_C rules are described:
  • This Gist
  • when you write your Keil code or ME code in CCS compiler then please don't copy your keil or ME IDE project files.
  • If you select the target file MSP430 or others in CCS copiler then please read first the user manual & datasheet of this embedded chip.
  • Here i select MSP430 as a target and device MSP430F5527 and linker MSP430F5527.cmd. So ,read first MSP430 user guide and MSP430F5527 datasheet.
  • If you paste your Keil or ME code into CCS IDE then show lot of error. But keep in head we used the CCS only for remove the warning.Because there we write the program based on 8051 microcontroller or PIC18F458 microcontroller not based on TI MSP430F5527 microcontroller.
  • So next step you write your code into MSP430 format just modify the register or Port selection. Just example when you select a Port or pin in 8051 microcontroller then we used "sbit" instruction. if anyone write "sbit" instruction in CCS then you show a error "sbit" not found. So for port or pin selection of MSP430F5527 you write in there PXDIR,PXOUT, PXIN where X is no of port 0 to 7 or 9. so, read msp430 use guide.
  • After write your coding , now you build the project then show no error but have warnings.
  • Then you go "Project Explorer window " and right click on your project and go to properties and then show the properties windows.
  • After that clicK "Build" and go to Advanced Option. Click on Advanced Option you get MISRA_C(2004) rule and clicK on. _ Not select all rules at time.
  • Please select on rule means rule 1.1 and build it. Then show the warning in a line , you go this line and solve this warning. You please read the MISRA rule and if you not got any idea for solve the warning then please help on Internet.
  • Same steps follow up to rule 20.
  • When complete the rule checking then you make your coding no error with no warning.
  • Then you compare the two codes one is before MISRA testing and other is after MISRA testing.
  • So,then follow the updates of your coding and then follow or update the code of your Keil or ME IDE.
  • After that compile or Build the Keil or ME IDE , you see you project successfully compiled with no error and no warning.

How to improved your 8051 or PIC18 project code after MISRA-C testing.

It is very important for every programmer that after checking MISRA_c for remove warning problem and then you write your update code in Keil or ME IDE and again build it, then show that your programming is compiled successfully with 0 error and 0 warning. That's our main object.

  • So question is that CCS project code is compiled in Keil or ME IDE? That would be possible by you create a function prototype where you describe chip information means you write in there MSP430F5527 microcontroller's registers information or 8051 microcontroller or PIC18F458 microcontroller information. Follow these steps:

  • First we create function and name it "void XXX_operation(void);" then you call these function in your main function. void main(void) { XXX_operation(); }

  • Now we declare a function and write in this function the microcontroller's registers & port define means if you working in CCS IDe then write down MSP430F5527 microcontroller register and port define in there.If you working on Keil or ME IDE then define 8051 or PIC18F458 microcontroller register and port selection function in there respectively.

  • How can i write this: For CCS IDE you write down for a port selection "PXDIR= 0xFF;" 1 for output and 0 for input then used PXOUT or PXIN for pin value high or low. For 8051 microcontroller you write "sbit" and "sfr" for pin and port selection respectively. For PIC18F458 microcontroller you write: "#define GLCD_Dir TRISD char GLCD_DataPort at PORTD;" for port selection and "sbit GLCD_CS1 at LATB0_bit; sbit GLCD_CS1_Direction at TRISB0_bit;" for pin selection.

  • Now you write down in void XXX_operation(void); /* function prototype / void XXX_operation(void) { volatile unsigned char z; switch(z) { case 1: / for CCS IDE */ {

            #define led1       0x0001
            #define led2       0x0002
            #define led3       0x0004
            #define led4       0x0008
            #define led5       0x0010
             P2DIR |= led1;                                         /*  Set P1.0 to output direction....*/
             P2OUT &= ~led1;                                 /*  Set led1 off.....*/
            P2DIR |= led2;                                         /*  Set P1.1 to output direction....*/
             P2OUT &= ~led2;                                 /*  Set led1 off....*/
              P2DIR |= led3;                                         /*  Set P1.2 to output direction....*/
              P2OUT &= ~led3;                                 /*  Set led1 off...*/
              P2DIR |= led4;                                         /*  Set P1.3 to output direction....*/
              P2OUT &= ~led4;                                 /*  Set led1 off....*/
             P2OUT &= ~led5;                                 /* Set led1 off.....*/
              P1SEL &= ~0x08;                                        /*  Select Port 1 P1.3 (RC5 sensor)....*/
             P1DIR &= ~0x08;                                        /*  Port 1 P1.3 (RC5 sensor) as input, 0 is input....*/
             P1REN |= 0x08; 
         }
       case 2: /* for Keil IDE   */
         {
          sbit led1=P2^0;   /* select P2.0 as a led1   */
          sbit led2=P2^1;   /* select P2.1 as a led2   */
          sbit led3=P2^2;   /* select P2.2 as a led3   */
          sbit led4=P2^3;   /* select P2.3 as a led4   */
          sbit led5=P2^4;   /* select P2.4 as a led5   */
          sbit RC5=P3^2;    /* select P3.2 as a RC5  */
           }
        case 3:
         {
            const register unsigned short int RC51=2;
            sbit RC51_bit at PORTD.B2;
            const register unsigned short int LED1=0;
            sbit LED1_bit at PORTA.B0;
            const register unsigned short int LED2=1;
            sbit LED2_bit at PORTA.B1;
            const register unsigned short int LED3=2;
            sbit LED3_bit at PORTA.B2;
             const register unsigned short int LED4=3;
            sbit LED4_bit at PORTA.B3;
            const register unsigned short int LED5=4;
            sbit LED5_bit at PORTA.B4;    
          }
    

    }

  • Now here z is the integer value which select the IDE when you select 1 then CCS IDE and 2 or 3 are Keil or ME IDE.

  • So ,if you declare at main function the value of z value then possible for same programming code running in CCS/Keil/ME IDE.

  • It is like as switch if you select 1 then CCS, 2 for Keil and 3 for ME IDE respectively.

CAN(control Area Network) BUS based machine control used in Automation Industry(CAN BASED MULTI MOTOR MOTION OR RPM CONTROL AND DATA ACQUISIOTION USING BY A PC).

Basic Block Diagram of CAN Bus model:

CAN BUS CAN BUS

Abstract:

  • Controller Area Network (CAN) has long been used for automation application as a method to enable robust serial communication. The goal was to make the system more reliable, safe, and efficient while decreasing wiring harness weight and complexity. Controller Area Network is a multi-master, message broadcast system that can operate at maximum signaling rate of 1 Mbps (Megabits per second). CAN bus is a two wire bus used for serial communication. The various advantages of CAN bus are discussed over other serial buses like MOD bus. Based on these factors, a CAN bus system in building automation, Process Automation System, Security system, Distributed control System, Quality control machine etc. This project shall focus on application of CAN bus in multi motor motion control.

The multi motor motion control system is developed using the principles and described in below:

CAN BUS

  • Here sensor1, sensor2, sensor3, keypad, touch screen (TFT), keypad and rS232 are connected to the main controller or node1. Sensors are used as per depends on industry means which condition are used for control the motor. Keypad is used for manual control means each key has a different operation. Touch screen used for modified or updated system for viewers. Rs232 or USB used for serial communication with PC. PC used for automation, data control, and automatic control. Node2 is subsystem of main controller. Temperature sensor LM35 is connected to the node2 .Generally it is used for measure the temperature of surrounding and one fan is used for control the temperature. Node3 is another subsystem in this project. Here two motor are connected with node3. Pic18f458 has a two PWM, so if industry needed more motor then just increased the no of node or subsystem.
  • Here the baud rate is selected 1Mbps in between node1 and node3. Secondly, here another baud rate is selected in between node1 and node2 which is 500Kbps.
  • Another point is very important for control the motion of motor, here RPM sensor means simply IR Led and photo-diode used .Here two RPM sensors are used for control the motion or speed of the motor.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment