SPI TWRMCF51CN Driver Usage

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

SPI TWRMCF51CN Driver Usage

跳至解决方案
1,603 次查看
Gabrielus
Contributor I

HI,

 

I am using the TWRMCF51CN with CW10 and I am trying use the SPI0 port to read SPI device but I can't start driver. when I am debugging the spifd become null.

 

This is the code:

 

 

 

int sendData2(char *data){
    FILE_PTR spifd;
    spifd = fopen("spi0:", (pointer)(SPI_DEVICE_MASTER_MODE));
    if(spifd == NULL){ //<- before fopen the spifd is NULL
        printf("error opening CS Driver");
    }
}

 

 

and this is the modified vars in user_config.h

 

 

#define BSPCFG_ENABLE_ADC        0   /* <- Change to 0 NOTE: Shares wires with I2C1, SPI0 */
#define BSPCFG_ENABLE_SPI0       1   /* <- Change to 1 NOTE: Shares wires with I2C1, ADC */   

 

 

I trying a lot configurations, but I have the same error.

 

Please giveme help.

Regards.

Gabriel

 

0 项奖励
1 解答
781 次查看
PetrM
Senior Contributor I

Please check if the user_config.h you changed was the one in config directory (not in lib).

You have to recompile libraries after that also.

It's hard to tell what is the cause, could you debug the fopen function more to see, if it finds the driver according to given name? You can also set breakpoint into _mcf5xxx_spi8_polled_init() function in spi_pol_mcf5xxxx_spi8.c to check if it even gets there.

 

PetrM

 

在原帖中查看解决方案

0 项奖励
5 回复数
782 次查看
PetrM
Senior Contributor I

Please check if the user_config.h you changed was the one in config directory (not in lib).

You have to recompile libraries after that also.

It's hard to tell what is the cause, could you debug the fopen function more to see, if it finds the driver according to given name? You can also set breakpoint into _mcf5xxx_spi8_polled_init() function in spi_pol_mcf5xxxx_spi8.c to check if it even gets there.

 

PetrM

 

0 项奖励
781 次查看
Gabrielus
Contributor I

Yes the problem was solve importing bsp_twrmcf51cn and I modified user_config.h and compiled as Release and Everything was OK. 

 

Thanks

0 项奖励
781 次查看
javax
Contributor I

Hi everybody

I just found this thread  suitable for my question.

 

I am building an application where I use SPI1 on the MCF51CN128 tower. Some times I require to handle SPI1 pins as

GPIO.  Before I open a spi_file(MQX_FILE_PTR) I can do this by a GPIO_PIN_STRUCT,  but after opening spi_file, commands over GPIO_PIN_STRUCT don´t work. I have tried closing spi_file before handling GPIO but it doesn´t work

 

I´ll appreciate any help.

0 项奖励
781 次查看
javax
Contributor I

Just another question..How can I uninstall a device driver in a MQX frame.

Thanks

0 项奖励
781 次查看
PetrM
Senior Contributor I

You can uninstall driver using _io_dev_uninstall() function, i.e. _io_dev_uninstall ("spi1:");

 

The gpio pin handling is done in "overwrite manner" - the last driver opened resets the pins for its purpose.

 

If you have to toggle between gpio driver and spi driver, you don't have to uninstall them, just close one and open again the other.

 

 

while (1) {

   fopen ("spi1:", NULL);

   ....

   fclose (spifd);

 

   fopen ("gpio:", ...);

   ...

   fclose (gpiofd);

}

 

 

PetrM

 

0 项奖励