GPIO simple output with kinetis kwikstik

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

GPIO simple output with kinetis kwikstik

跳至解决方案
3,505 次查看
alexdev83
Contributor II

Hi, I'm trying to write a simple program for make blinking a led linked on GPIO pin 6 of my Kwikstik (with the TWR-ELEV).

 

I'm working with Codewarrior 10.1 (with the lastest update patch) and MQX 3.7 + KwikStik Patch.

 

This the code I have wrote. The codewarrior compile without errors but it not work..

 

#include "main.h"

#include <io_gpio.h>
#include <io_gpio_kgpio.h>




#if !BSPCFG_ENABLE_IO_SUBSYSTEM
#error This application requires BSPCFG_ENABLE_IO_SUBSYSTEM defined non-zero in user_config.h. Please recompile BSP with this option.
#endif


#ifndef BSP_DEFAULT_IO_CHANNEL_DEFINED
#error This application requires BSP_DEFAULT_IO_CHANNEL to be not NULL. Please set corresponding BSPCFG_ENABLE_TTYx to non-zero in user_config.h and recompile BSP with this option.
#endif


TASK_TEMPLATE_STRUCT MQX_template_list[] =
{
/*  Task number, Entry point, Stack, Pri, String, Auto? */
   {MAIN_TASK,   Main_task,   1500,  9,   "main", MQX_AUTO_START_TASK},
   {0,           0,           0,     0,   0,      0,                 }
};

GPIO_PIN_STRUCT pins1[] = {
        
    GPIO_PORT_A | GPIO_PIN6,
    GPIO_LIST_END
};
/*TASK*-----------------------------------------------------
*
* Task Name    : Main_task
* Comments     :
*    This task prints " Hello World "
*
*END*-----------------------------------------------------*/

void Main_task(uint_32 initial_data)
{
    MQX_FILE_PTR file1;

    
   _io_gpio_install("gpio:");
   
   file1 = fopen("gpio:write", (char_ptr) &pins1);
   
   


while (1) {

     
       _io_ioctl(file1, GPIO_IOCTL_WRITE_LOG1, NULL);
       
       _time_delay(1000);
       
       _io_ioctl(file1, GPIO_IOCTL_WRITE_LOG0 NULL);
       
       _time_delay(1000);
}   
   //_mqx_exit(0);


/* EOF */

-------------------------------------------------------------------------------------------------------------------------------------------

 

I have already set to one GPIO in userconfig.h

 

Someone find errors in this code?

 

Thanks

 

0 项奖励
回复
1 解答
2,641 次查看
alexdev83
Contributor II

I have resolved my problem!

The mistake that I commit is that I confuse Name and Usage of Tower Elevator Connections in Kwikstik Manual!!

Thanks however for your responses!
 

在原帖中查看解决方案

0 项奖励
回复
10 回复数
2,641 次查看
c0170
Senior Contributor III

HI,

 

There are no LEDs you can blink on kwikstik. I assume you connected your own LED to PTA6 pin.

Also you should check return values if file is opened and you write logical values to the pin.

 

Start with LWGPIO which is much easier to use.

 

Regards,

MartinK

0 项奖励
回复
2,640 次查看
alexdev83
Contributor II

Thanks for your response, I have tried with LWGPIO, but the result is the same.

 

This is my code (I want only turn on a led connected on GPIO6, in the side A expansion port of the tower):

--------------------------------------------------------------------------------------------------------------------------

#include <mqx.h>
#include <bsp.h>
#include <lwgpio.h>
#include <lwgpio_kgpio.h>


 

void main_task
   (
      uint_32 initial_data
   )
{
    
    boolean status;
    LWGPIO_STRUCT led1;
    
    status = lwgpio_init(&led1, LWGPIO_PORT_A | LWGPIO_PIN6, LWGPIO_DIR_OUTPUT, LWGPIO_VALUE_HIGH);
    if (status != TRUE) {
        printf("LWGPIO FAIL.\n");

    }
    else
    {
        printf("LWGPIO OK.\n");

    }
    
    while (TRUE);

    };
/* EOF */
}

-------------------------------------------------------------------------------------------------------------------------------------------------

I also tried this:

 

status = lwgpio_init(&led1, LWGPIO_PIN6, LWGPIO_DIR_OUTPUT, LWGPIO_VALUE_HIGH);

 

in the codewarrior console i see "LWGPIO OK" but the led don't turn on...

 

Do you see errors in my code?

Or the problem are the power connection on the tower? (I Have the Kwikstik connected the to PC with USB cable in Jlink connector and the twr-elev connected to the pc with USB cable in S4 connector and SW1 switch turned on)

 

 

 

0 项奖励
回复
2,641 次查看
MarkP_
Contributor V

Hi,

you need also set the io-pin mode by function lwgpio_set_functionality().

Example:

lwgpio_set_functionality(&led1, LWGPIO_MUX_PTA6_GPIO);

~Mark

 

0 项奖励
回复
2,641 次查看
alexdev83
Contributor II

I modified the code:

----------------------------------------------------------------------------------------------------------------------------------------------------------------

void main_task
   (
      uint_32 initial_data
   )
{
    LWGPIO_STRUCT led1;
    boolean status;
      
        
        status = lwgpio_init(&led1, LWGPIO_PORT_A | LWGPIO_PIN7, LWGPIO_DIR_OUTPUT, LWGPIO_VALUE_HIGH);
        if (status != TRUE) {
            printf("LWGPIO FAIL.\n");

        }
        else
        {
            printf("LWGPIO OK.\n");

        }
        
        lwgpio_set_functionality(&led1, LWGPIO_MUX_A7_GPIO);
        lwgpio_set_value(&led1, LWGPIO_VALUE_HIGH);
        
        while (TRUE){
            //test

        }


}

------------------------------------------------------------------------------------------------------

but the problem is the same. (If I make the debug,   lwgpio_set_functionality and lwgpio_set_value returns a non zero value)

0 项奖励
回复
2,641 次查看
c0170
Senior Contributor III

Hello alexdev83,

 

why did you connect LED to PTA7 ? That pin is for Microphone signal (schematic for kwikstik, page9). Try another pin.

 

I run an example where i toogled GPIO_PORT_A | GPIO_PIN12.

 

Regards,

MartinK

0 项奖励
回复
2,641 次查看
alexdev83
Contributor II
Sorry, but in kwikstik manual i don't see gpio pin12. Where is connected?
0 项奖励
回复
2,641 次查看
c0170
Senior Contributor III
0 项奖励
回复
2,641 次查看
alexdev83
Contributor II

I saw the scheme you indicate. But i haven't a connector for link the led to the TWRPI SOCKETS.

 

Can you say me where I can link the led in the A Side expansion port of the TWR-ELEV and a simple code for make power on the led?

 

 

Thanks

0 项奖励
回复
2,641 次查看
alexdev83
Contributor II

(The schematics that you linked to me is relative to TWR-K40X256, not to Kwikstik I have!!!!)

0 项奖励
回复
2,642 次查看
alexdev83
Contributor II

I have resolved my problem!

The mistake that I commit is that I confuse Name and Usage of Tower Elevator Connections in Kwikstik Manual!!

Thanks however for your responses!
 

0 项奖励
回复