Problem with USB VCOM and Timer

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problem with USB VCOM and Timer

569 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Digelo on Sun Aug 23 08:49:06 MST 2015
Hi
I got a code for communicating through USB VCOM and its work with hyperterminal when i try to add a timer to my code hyperterminal no longer can open my device VCOM USB port.
it would be nice if u guys can help me i spent 3days on it already and still cant fix this issue.

//in the name of ALLAH
#include "LPC17xx.h"
#include "lpc17xx_gpio.h"
#include "cmsis_os.h"
#include "rl_usb.h"
#include "Driver_USART.h"

extern ARM_DRIVER_USART Driver_USART1;

#define BUF_SZ 128
// UART -> USB
uint8_t  uart2usb_buf[BUF_SZ];
volatile uint32_t uart2usb_in;
volatile uint32_t uart2usb_out;
// USB -> UART
uint8_t  usb2uart_buf[BUF_SZ];
volatile bool uart_send_busy;
         bool bridge_ready  =  false;
volatile bool uart_setup[2] = {false, false};

void USART1_Callback (uint32_t event) {

  if ( event &  ARM_USART_EVENT_SEND_COMPLETE) {
    uart_send_busy = false;
  }
  if ( event &  ARM_USART_EVENT_RECEIVE_COMPLETE) {
    uart2usb_in += BUF_SZ;
    Driver_USART1.Receive(uart2usb_buf, BUF_SZ);
  }
}

uint32_t tmmr;
uint32_t Pulser;
uint32_t Zpulse;
uint32_t Takh;
uint32_t Ztakh;
uint32_t Frq;
uint32_t Freq;
uint32_t Halprob;
uint32_t Shoro;
uint8_t eimbuf[32];
volatile uint32_t rdcnt;

void microinit(void);
void TIMER0_IRQHandler(void);
void sRead(void);
void sWrite(uint32_t wrcnt);
void nemidunamUSB(void);


void MicroInit(void){

        USBD_Initialize    (0);               // USB Device 0 Initialization
USBD_Connect       (0);               // USB Device 0 Connect

//Wait until first USB Device is configured
while (USBD_Configured (0) == 0);

//LPC_SC-> PCONP |= (1 << 0);
//LPC_TIM0->TCR |= 0x02;       // reset timer 
//LPC_TIM0->PR  = 100;       
                //LPC_TIM0->MR0 = 240000;
                //LPC_TIM0->IR  = 0xff;       // reset interrrupt
                //LPC_TIM0->MCR = 0x03; 
//NVIC_EnableIRQ(TIMER0_IRQn);
//LPC_TIM0->TCR = 0x01;       // start timer

}
void TIMER0_IRQHandler(void)
{
    LPC_TIM0->IR  = 0x01;       // reset all interrrupts 

         Pulser--;
         if(Pulser == 0)

         Takh--;
         if(Takh == 0)

         Frq++;
}
void nemidunamUSB(void){
 if (USBD_Configured (0)) {
      if (uart_setup[0]) {
        bridge_ready   = true;
        uart_setup[0]  = false;
        uart_send_busy = false;
        uart2usb_in    = 0;
        uart2usb_out   = 0;
        Driver_USART1.Receive(uart2usb_buf, BUF_SZ);
}
}
}
void sRead(void){
if (bridge_ready) {
if ((rdcnt = USBD_CDC_ACM_DataAvailable(0)) > 0) {
USBD_CDC_ACM_ReadData(0, eimbuf, rdcnt);
}
}
}
void sWrite(uint32_t wrcnt){
USBD_CDC_ACM_WriteData (0,(const uint8_t*)&eimbuf,wrcnt);
}
int main(void)
{
MicroInit();
while(1){
nemidunamUSB();
sRead();
sWrite(rdcnt);
}

  //  return 0;
}


this code wortk untill i add for example this line :

           LPC_TIM0->TCR |= 0x02;       // reset timer 


if i add this or any timer config instructions hyperterminal no longer can open my device VCOM port.

Original Attachment has been moved to: eimMotor2.zip

Labels (1)
0 Kudos
0 Replies