don't probe a sensor after applying usb driver

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

don't probe a sensor after applying usb driver

跳至解决方案
2,176 次查看
itr1718
Contributor III

Hello,

 

I am using a mcu, MKL27Z256 and a gas sensor, SGP30.

I would like to transfer sensor data to usb.

I have two codes which transfer string to usb through a terminal program and transfer sensor data to console window with printf function. 

They work seperately very good. 

If I mix them, I mean to transfer sensor data to usb, sensor probing is failed. 

I copied just usb driver files into my project and initialised usb connection.

 

Has someone already had similary problems and solved?

0 项奖励
回复
1 解答
2,138 次查看
myke_predko
Senior Contributor III

Hiya @itr1718 

I'm asking we bring the "Clock tact between USB CDC and I2C" thread into this one.  

It appears that you are bringing in code from multiple sources and selectively applying them without understanding the different platforms and SDKs they were written for.  

I believe that there are three drvier pieces that are needed to be coordinated before you can expect to get a working application and I don't think that's happening.  

Just so we're clear the three Driver pieces are:

  1. Clock Driver (System which includes USB and I2C)
  2. USB Driver
  3. I2C Driver

Ideally, each are from the same SDK (the latest one available for your target processor).  Along with that, I highly recommend that you use MCUXpresso for configuring your system.  The Clock and Pins Wizards should be used for specifying your IO.  The USB Driver should be from the SDK examples and I recommend the bare metal ("cdc_vcom_bm") code for your base.  

To keep things simple, I suggest that you create a formatted string from your sensor data using sprintf and passing it to the USB send function rather than trying to convert printf to use USB (a *lot* less work and much easier to debug and there should be very little difference in final application size).  

Could you confirm that the drivers you're using are from the same SDK and that you can use the Clocks and Pin Wizard in MCUXpresso?

myke

在原帖中查看解决方案

0 项奖励
回复
7 回复数
2,161 次查看
myke_predko
Senior Contributor III

Hi @itr1718 

Can you give us a better description of your code?  Also a better description of your set up would be helpful - it sounds like you have a "terminal program" and a "console window" as separate interfaces to the board (is it a Freedom/Tower board).   

Are you using the USB CDC demo code as your base?  

Without providing your whole project, could you show us how you are trying to send data via USB?  

myke

0 项奖励
回复
2,154 次查看
itr1718
Contributor III

Hi @myke_predko ,

I have a terminal program, putty, and also use console in IDE to check values.

 

I am using a usb cdc driver demo for FRDM-K27L. All codes for usb cdc are from the demo and clock_config setting is also followed from that. I tried to send some string and numbers via USB.

But I didn't try for sensor data, because usb_echo for usb cdc can't print sent float and double values.

 

I replied on the other question with detail clock_config and i2c initialisation. 

0 项奖励
回复
2,148 次查看
myke_predko
Senior Contributor III

Hi @itr1718 

I'm using the K22 SDK code and I'm sending data using:

error = USB_DeviceCdcAcmSend(s_cdcVcom.cdcAcmHandle
                           , USB_CDC_VCOM_BULK_IN_ENDPOINT
                           , mainMsg.msg
                           , mainMsg.size);
if (error != kStatus_USB_Success) {
/* Failure to send Data Handling code here */
}

What are you using and see my previous comments about clocking.

myke

0 项奖励
回复
2,141 次查看
itr1718
Contributor III

Hi @myke_predko ,

I understand what you wanted.

I would use the function PRINTF. I followed How to use CDC VCOM example with printf with SDK_2... - NXP Community and implemented for that.

 

This is my sending data below:

void VirtualCom_SendDataBlocking(uint32_t base, const uint8_t *buf, uint32_t count)
{
    usb_status_t error = kStatus_USB_Success;
    int i = 1000;
    if ((buf == NULL) || (base == NULL)){
      error = kStatus_USB_InvalidParameter;
    }else{
        if ((1 != s_cdcVcom.attach) && (1 != s_cdcVcom.startTransactions)){
        error=kStatus_USB_ControllerNotFound;
        }else{
          memcpy(s_currSendBuf, buf, count > DATA_BUFF_SIZE ? DATA_BUFF_SIZE : count);
          if (USB_DeviceSendRequest(s_cdcVcom.deviceHandle,       USB_CDC_VCOM_BULK_IN_ENDPOINT, s_currSendBuf, count) != kStatus_USB_Success){
      /* Failure to send Data Handling code here */
          } else {
      /* Wait until transmission are done */   
          while (!g_sendFinished) {
            i--;
            if(i == 0)
            g_sendFinished = 1;
          };
        g_sendFinished = 0;
        }
      }
    }
}

0 项奖励
回复
2,139 次查看
myke_predko
Senior Contributor III

Hiya @itr1718 

I'm asking we bring the "Clock tact between USB CDC and I2C" thread into this one.  

It appears that you are bringing in code from multiple sources and selectively applying them without understanding the different platforms and SDKs they were written for.  

I believe that there are three drvier pieces that are needed to be coordinated before you can expect to get a working application and I don't think that's happening.  

Just so we're clear the three Driver pieces are:

  1. Clock Driver (System which includes USB and I2C)
  2. USB Driver
  3. I2C Driver

Ideally, each are from the same SDK (the latest one available for your target processor).  Along with that, I highly recommend that you use MCUXpresso for configuring your system.  The Clock and Pins Wizards should be used for specifying your IO.  The USB Driver should be from the SDK examples and I recommend the bare metal ("cdc_vcom_bm") code for your base.  

To keep things simple, I suggest that you create a formatted string from your sensor data using sprintf and passing it to the USB send function rather than trying to convert printf to use USB (a *lot* less work and much easier to debug and there should be very little difference in final application size).  

Could you confirm that the drivers you're using are from the same SDK and that you can use the Clocks and Pin Wizard in MCUXpresso?

myke

0 项奖励
回复
2,123 次查看
itr1718
Contributor III

Hi @myke_predko ,

I compared the examples, i2c and usb cdc, from SDK again and followed them.

I changed I2C Baud rate from 400000U to 100000U and It works now.

 

Thank you for your help.

itr

2,119 次查看
myke_predko
Senior Contributor III

@itr1718 

Great job getting your application working!

myke

0 项奖励
回复