SPI TWRMCF51CN Driver Usage

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

SPI TWRMCF51CN Driver Usage

ソリューションへジャンプ
1,609件の閲覧回数
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 解決策
787件の閲覧回数
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 返答(返信)
788件の閲覧回数
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 件の賞賛
787件の閲覧回数
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 件の賞賛
787件の閲覧回数
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 件の賞賛
787件の閲覧回数
javax
Contributor I

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

Thanks

0 件の賞賛
787件の閲覧回数
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 件の賞賛