This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

I2C-Master in RTX

i have the same problem with an LPC1788 (Cortex M3)

It works with multitasking!
i use the i2c master!
As long as I do not use the function i2c master The program works fine works
But if I use the function i2c master Micro does not work!

Thank you for your help

Parents
  • hi
    my code is
    i2c master code is

    #include "lpc177x_8x_i2c.h"
    #include "lpc177x_8x_pinsel.h"
    char seg=193,value;
    #define I2CDEV_M                (2)
    #define I2CDEV_S_ADDR   (0x21)
    #define I2CDEV_TRANSFER_POLLING        0
    #define BUFFER_SIZE                     0x10
    
    __IO uint8_t Master_Buf[BUFFER_SIZE];
    __IO uint8_t master_test[2];
    __IO Bool complete;
    
    #if (I2CDEV_TRANSFER_POLLING == 0)
    #if ((I2CDEV_M == 0))
    void I2C0_IRQHandler(void)
    #elif ((I2CDEV_M == 1))
    void I2C1_IRQHandler(void)
    #elif ((I2CDEV_M == 2))
    void I2C2_IRQHandler(void)
    #else
    void I2C_IRQHandler(void)
    #endif
    {
             I2C_MasterHandler((en_I2C_unitId)I2CDEV_M);
            if (I2C_MasterTransferComplete((en_I2C_unitId)I2CDEV_M)){
                      complete = TRUE;
            }
    }
    #endif
    
    extern pcf8574(char valu[])
    {
    
            I2C_M_SETUP_Type transferMCfg;
            uint32_t tempp;
            uint8_t *pdat;
    #if ((I2CDEV_M == 0))
            PINSEL_ConfigPin (5, 2, 5);
            PINSEL_ConfigPin (5, 3, 5);
    #elif ((I2CDEV_M == 1))
            PINSEL_ConfigPin (0, 19, 3);
            PINSEL_ConfigPin (0, 20, 3);
            PINSEL_SetOpenDrainMode(0, 19, ENABLE);
            PINSEL_SetOpenDrainMode(0, 20, ENABLE);
            PINSEL_SetPinMode(0, 19, PINSEL_BASICMODE_PLAINOUT);
            PINSEL_SetPinMode(0, 20, PINSEL_BASICMODE_PLAINOUT);
    #elif ((I2CDEV_M == 2))
            PINSEL_ConfigPin (0, 10, 2);
            PINSEL_ConfigPin (0, 11, 2);
            PINSEL_SetOpenDrainMode(0, 10, ENABLE);
            PINSEL_SetOpenDrainMode(0, 11, ENABLE);
            PINSEL_SetPinMode(0, 10, PINSEL_BASICMODE_PLAINOUT);
            PINSEL_SetPinMode(0, 11, PINSEL_BASICMODE_PLAINOUT);
    #else
            while(1);
    #endif
    
            I2C_Init((en_I2C_unitId)I2CDEV_M, 100000);
            I2C_Cmd((en_I2C_unitId)I2CDEV_M, I2C_MASTER_MODE, ENABLE);
                    if((strcmp("1",valu))==0){
                    GPIO_ClearValue(4,(1<<16));
            seg=207;//1
            }
            transferMCfg.sl_addr7bit = I2CDEV_S_ADDR;
            transferMCfg.tx_data=&seg;
            transferMCfg.tx_length = 1;
            transferMCfg.rx_data = NULL;
            transferMCfg.rx_length = 0;
            transferMCfg.retransmissions_max = 3;
            transferMCfg.tx_count = 0;
            transferMCfg.rx_count = 0;
            transferMCfg.retransmissions_count = 0;
    #if (I2CDEV_TRANSFER_POLLING == 0)
            complete = FALSE;
            I2C_MasterTransferData((en_I2C_unitId)I2CDEV_M, &transferMCfg, I2C_TRANSFER_INTERRUPT);
            while(!complete);
    #else
            I2C_MasterTransferData((en_I2C_unitId)I2CDEV_M, &transferMCfg, I2C_TRANSFER_POLLING);
    #endif
                    complete = FALSE;
              I2C_MasterTransferData((en_I2C_unitId)I2CDEV_M, &transferMCfg, I2C_TRANSFER_INTERRUPT);
              while(!complete);
                    value = !value;
                    seg=0;
            }
    
    

    and

    my rtx code is

     #include "lpc177x_8x.h"
    //      #include "display_lcd.h"
    //      #include "timer.h"
    //      #include "lpc_types.h"
            #include "LCD.h"
            #include "rtc.h"
    //      #include "shasti.h"
            #include "pcf8574.h"
    //      #include <key_setting.h>
    //      #include "revision.h"
             #include <RTL.h>
    
            OS_TID   tsk_ID1, tsk_ID2, tsk_ID3, tsk_ID4, tsk_ID5, tsk_ID6, tsk_ID7, tsk_ID8;
    OS_SEM semaphore1;
    __task void task_init(void);
    __task void task1(void);
    __task void task2(void);
    __task void task3(void);
    __task void task4(void);
    __task void task5(void);
    __task void task6(void);
    __task void task7(void);
    __task void task8(void);
    
    
    
    
    
    
    
            int main(void){
    //      c_entry();
    //      rtc_c_entry();
    //      red_eeprom();
    //
            lcd_init();
            lcd_init();
            lcd_clear();
            //Delay(0xfffff);
            PINSEL_ConfigPin (4, 16, 0);
            GPIO_SetDir(4,(1<<16),1);
      lcd_backlight_on();
                      SystemInit(); /* initialize the Coretx-M3 processor */
                        os_sys_init(task_init);
    
    //return c_entry_pcf8574();
        while (1) {
    //pcf8574("1");
    }  // ino nezarinam farghi nemikone chon asan barname be inja nemirese !
        return 0;
            }
    
    
            __task void task_init(void)
    {
    
       os_sem_init (semaphore1, 1);
       tsk_ID1 = os_tsk_create(task1, 1); // priority:1
       tsk_ID2 = os_tsk_create(task2, 1);
       tsk_ID3 = os_tsk_create(task3, 1);
       tsk_ID4 = os_tsk_create(task4, 4);
       tsk_ID5 = os_tsk_create(task5, 5);
       tsk_ID6 = os_tsk_create(task6, 6);
       tsk_ID7 = os_tsk_create(task7, 7);
       tsk_ID8 = os_tsk_create(task8, 8);
    
       os_tsk_delete_self();    // necessary
    }
    //------------ 1 --------------
    __task void task1(void)
    {
    
       int i = 0;
    
                    PINSEL_ConfigPin (2, 1, 0);
                    GPIO_SetDir(2,(1<<1),1);
     os_itv_set(100);
       while(1){
                     os_sem_wait (semaphore1,1);
          os_itv_wait();
    
          if (i == 0)
          {
           GPIO_SetValue(2,(1<<1));
             i = 1;
          }
          else
          {
             GPIO_ClearValue(2,(1<<1));
             i = 0;
          }
                            os_sem_send (semaphore1);
       }
    }
    //------------ 2 --------------
    __task void task2(void)
    {
       int i = 0;
                    PINSEL_ConfigPin (3, 20, 0);
                 GPIO_SetDir(3,(1<<20),1);
       os_itv_set(100);
       while(1){
                     os_sem_wait (semaphore1, 0xffff);
          os_itv_wait();
          if (i == 0)
          {
            GPIO_SetValue(3,(1<<20));
             i = 1;
          }
          else
          {
             GPIO_ClearValue(3,(1<<20));
             i = 0;
          }
                            os_sem_send (semaphore1);
       }
    }
    //------------ 3 --------------
    __task void task3(void)
    {
    
       int i = 0;
    
       while (1)
       {
                     os_sem_wait (semaphore1, 0xffff);
          os_dly_wait(1);
          if (i == 0)
          {
           display_time();
             i = 1;
          }
          else
          {
                            //tsk_lock();
                            //      pcf8574("1");
                                    //tsk_unlock();
             i = 0;
          }
                    os_sem_send (semaphore1);
       }
    }
    

    i dont use pcf8574("1"); my code working fine
    but i use pcf8574("1") in task3 my code Stuck to the task3 and

Reply
  • hi
    my code is
    i2c master code is

    #include "lpc177x_8x_i2c.h"
    #include "lpc177x_8x_pinsel.h"
    char seg=193,value;
    #define I2CDEV_M                (2)
    #define I2CDEV_S_ADDR   (0x21)
    #define I2CDEV_TRANSFER_POLLING        0
    #define BUFFER_SIZE                     0x10
    
    __IO uint8_t Master_Buf[BUFFER_SIZE];
    __IO uint8_t master_test[2];
    __IO Bool complete;
    
    #if (I2CDEV_TRANSFER_POLLING == 0)
    #if ((I2CDEV_M == 0))
    void I2C0_IRQHandler(void)
    #elif ((I2CDEV_M == 1))
    void I2C1_IRQHandler(void)
    #elif ((I2CDEV_M == 2))
    void I2C2_IRQHandler(void)
    #else
    void I2C_IRQHandler(void)
    #endif
    {
             I2C_MasterHandler((en_I2C_unitId)I2CDEV_M);
            if (I2C_MasterTransferComplete((en_I2C_unitId)I2CDEV_M)){
                      complete = TRUE;
            }
    }
    #endif
    
    extern pcf8574(char valu[])
    {
    
            I2C_M_SETUP_Type transferMCfg;
            uint32_t tempp;
            uint8_t *pdat;
    #if ((I2CDEV_M == 0))
            PINSEL_ConfigPin (5, 2, 5);
            PINSEL_ConfigPin (5, 3, 5);
    #elif ((I2CDEV_M == 1))
            PINSEL_ConfigPin (0, 19, 3);
            PINSEL_ConfigPin (0, 20, 3);
            PINSEL_SetOpenDrainMode(0, 19, ENABLE);
            PINSEL_SetOpenDrainMode(0, 20, ENABLE);
            PINSEL_SetPinMode(0, 19, PINSEL_BASICMODE_PLAINOUT);
            PINSEL_SetPinMode(0, 20, PINSEL_BASICMODE_PLAINOUT);
    #elif ((I2CDEV_M == 2))
            PINSEL_ConfigPin (0, 10, 2);
            PINSEL_ConfigPin (0, 11, 2);
            PINSEL_SetOpenDrainMode(0, 10, ENABLE);
            PINSEL_SetOpenDrainMode(0, 11, ENABLE);
            PINSEL_SetPinMode(0, 10, PINSEL_BASICMODE_PLAINOUT);
            PINSEL_SetPinMode(0, 11, PINSEL_BASICMODE_PLAINOUT);
    #else
            while(1);
    #endif
    
            I2C_Init((en_I2C_unitId)I2CDEV_M, 100000);
            I2C_Cmd((en_I2C_unitId)I2CDEV_M, I2C_MASTER_MODE, ENABLE);
                    if((strcmp("1",valu))==0){
                    GPIO_ClearValue(4,(1<<16));
            seg=207;//1
            }
            transferMCfg.sl_addr7bit = I2CDEV_S_ADDR;
            transferMCfg.tx_data=&seg;
            transferMCfg.tx_length = 1;
            transferMCfg.rx_data = NULL;
            transferMCfg.rx_length = 0;
            transferMCfg.retransmissions_max = 3;
            transferMCfg.tx_count = 0;
            transferMCfg.rx_count = 0;
            transferMCfg.retransmissions_count = 0;
    #if (I2CDEV_TRANSFER_POLLING == 0)
            complete = FALSE;
            I2C_MasterTransferData((en_I2C_unitId)I2CDEV_M, &transferMCfg, I2C_TRANSFER_INTERRUPT);
            while(!complete);
    #else
            I2C_MasterTransferData((en_I2C_unitId)I2CDEV_M, &transferMCfg, I2C_TRANSFER_POLLING);
    #endif
                    complete = FALSE;
              I2C_MasterTransferData((en_I2C_unitId)I2CDEV_M, &transferMCfg, I2C_TRANSFER_INTERRUPT);
              while(!complete);
                    value = !value;
                    seg=0;
            }
    
    

    and

    my rtx code is

     #include "lpc177x_8x.h"
    //      #include "display_lcd.h"
    //      #include "timer.h"
    //      #include "lpc_types.h"
            #include "LCD.h"
            #include "rtc.h"
    //      #include "shasti.h"
            #include "pcf8574.h"
    //      #include <key_setting.h>
    //      #include "revision.h"
             #include <RTL.h>
    
            OS_TID   tsk_ID1, tsk_ID2, tsk_ID3, tsk_ID4, tsk_ID5, tsk_ID6, tsk_ID7, tsk_ID8;
    OS_SEM semaphore1;
    __task void task_init(void);
    __task void task1(void);
    __task void task2(void);
    __task void task3(void);
    __task void task4(void);
    __task void task5(void);
    __task void task6(void);
    __task void task7(void);
    __task void task8(void);
    
    
    
    
    
    
    
            int main(void){
    //      c_entry();
    //      rtc_c_entry();
    //      red_eeprom();
    //
            lcd_init();
            lcd_init();
            lcd_clear();
            //Delay(0xfffff);
            PINSEL_ConfigPin (4, 16, 0);
            GPIO_SetDir(4,(1<<16),1);
      lcd_backlight_on();
                      SystemInit(); /* initialize the Coretx-M3 processor */
                        os_sys_init(task_init);
    
    //return c_entry_pcf8574();
        while (1) {
    //pcf8574("1");
    }  // ino nezarinam farghi nemikone chon asan barname be inja nemirese !
        return 0;
            }
    
    
            __task void task_init(void)
    {
    
       os_sem_init (semaphore1, 1);
       tsk_ID1 = os_tsk_create(task1, 1); // priority:1
       tsk_ID2 = os_tsk_create(task2, 1);
       tsk_ID3 = os_tsk_create(task3, 1);
       tsk_ID4 = os_tsk_create(task4, 4);
       tsk_ID5 = os_tsk_create(task5, 5);
       tsk_ID6 = os_tsk_create(task6, 6);
       tsk_ID7 = os_tsk_create(task7, 7);
       tsk_ID8 = os_tsk_create(task8, 8);
    
       os_tsk_delete_self();    // necessary
    }
    //------------ 1 --------------
    __task void task1(void)
    {
    
       int i = 0;
    
                    PINSEL_ConfigPin (2, 1, 0);
                    GPIO_SetDir(2,(1<<1),1);
     os_itv_set(100);
       while(1){
                     os_sem_wait (semaphore1,1);
          os_itv_wait();
    
          if (i == 0)
          {
           GPIO_SetValue(2,(1<<1));
             i = 1;
          }
          else
          {
             GPIO_ClearValue(2,(1<<1));
             i = 0;
          }
                            os_sem_send (semaphore1);
       }
    }
    //------------ 2 --------------
    __task void task2(void)
    {
       int i = 0;
                    PINSEL_ConfigPin (3, 20, 0);
                 GPIO_SetDir(3,(1<<20),1);
       os_itv_set(100);
       while(1){
                     os_sem_wait (semaphore1, 0xffff);
          os_itv_wait();
          if (i == 0)
          {
            GPIO_SetValue(3,(1<<20));
             i = 1;
          }
          else
          {
             GPIO_ClearValue(3,(1<<20));
             i = 0;
          }
                            os_sem_send (semaphore1);
       }
    }
    //------------ 3 --------------
    __task void task3(void)
    {
    
       int i = 0;
    
       while (1)
       {
                     os_sem_wait (semaphore1, 0xffff);
          os_dly_wait(1);
          if (i == 0)
          {
           display_time();
             i = 1;
          }
          else
          {
                            //tsk_lock();
                            //      pcf8574("1");
                                    //tsk_unlock();
             i = 0;
          }
                    os_sem_send (semaphore1);
       }
    }
    

    i dont use pcf8574("1"); my code working fine
    but i use pcf8574("1") in task3 my code Stuck to the task3 and

Children
  • Well, have you considered debugging?

    Why do I ask? Because your post doesn't give any indication that you have spent time checking where the function hangs.

    It will hang if you haven't correct values for I2CDEV_M.
    And it will hang if you don't get the interrupt that sets the completion flag.
    Have you even looked at the I2C pins and seen if there is any activity?

  • hello
    Thank you for your attention
    program i2c master Works well alone
    However, when this function is added to rtx
    the program (rtx+i2c ) hangs..
    in task1 blink led1
    and task2 blink led2
    When the program on hardware
    first led1 on
    second led2 on
    but when Performs task3 my code hangs
    (Note:i2c master code only works well)!!!
    but rtx + i2c master = hangs

  • If you do a task lock (or use a thread with highest priority) and call a function that hangs, then you are expected to get stuck.

    Still no indication that you have spent any time trying to figure out where in the I2C code you get stuck. That is still part of the debugging you should do.