interrupcion e impresion en arduino zero no me sale

Este es el codigo ya probe poner 2 en la funcion attachinterrupt e igual me imprime ceros

volatile unsigned long cnt0,cnt,d,j;
void setup() {
  pinMode(2, INPUT);
  attachInterrupt(14,r, CHANGE);
  Serial.begin(19200);
  cnt0=micros();
}
 
void loop(){
  //analogWrite(DAC1, value ); usar CDA
  analogWriteResolution(12);
  delay(5000);
  while(j<4096){
  analogWrite(8 ,j);
  delay(500);
  SerialUSB.println(d);
  j=j+40;
  }
  analogWrite(8 ,0);
}

void r(){
  cnt=micros();
  d=cnt-cnt0;
  cnt0=cnt;
}

Defines un

Serial.begin(19200);

y luego usas para imprimir datos

SerialUSB.println(d);

Para que fuera SerialUSB deberías haber definido el objeto SoftwareSerial indicando los pines para TX y RX. No esta en tu código así que corrige por Serial a secas.

SerialUSB.begin(19200); asi? es que con serial normal no funciona y este no lo se usar

Ahhh será que el Zero requiere eso? no lo sabía. Prueba mientras lo investigo.

Esto acabo de encontrar acerca del Zero

Serial - Puerto de programación (la ruta es SAMD->uart->EDBG->usb->PC)
Serial1 - Serial uart en pines 0 and 1
SerialUSB - Puerto nativo, Es un serial port emulado (USB-CDC)

Si estas usando SerialUSB y quieres ver los primeros datos enviados por el micro tienes que poner esto al comienzo del sketch esperando a que alguien abra el monitor Serie :

  SerialUSB.begin(9600);
  while (!SerialUSB) {
    ; // wait for serial port to connect
  }

Ya probe lo que mecionas, no funciono, encontre esto pero no se donde esta.

I solved my problem comment this line code in samd21_device.c:

uint8_t UDD_Recv_data(uint32_t ep, uint32_t len)
{
TRACE_DEVICE(printf("=> UDD_Recvdata : ep=%d\r\n", (char)ep):wink:

-> //if (len>64) len=64;
usb_endpoint_table[ep].DeviceDescBank[0].ADDR.reg = (uint32_t)&udd_ep_out_cache_buffer[ep];
-> //usb_endpoint_table[ep].DeviceDescBank[0].PCKSIZE.bit.MULTI_PACKET_SIZE = len;
usb_endpoint_table[ep].DeviceDescBank[0].PCKSIZE.bit.BYTE_COUNT = 0;
udd_OUT_transfer_allowed(ep);
TRACE_DEVICE(printf("=> UDD_Recv_data : data=%lu\r\n", (unsigned long)data):wink:

/* Wait for transfer to complete /
while (!udd_is_OUT_transf_cplt(ep));
/
Clear Transfer complete 0 flag */
udd_clear_OUT_transf_cplt(ep);

return udd_ep_out_cache_buffer[ep][0];
}

I discovered that when sending a string with a size x, the next string of the same size was read correctly. But if the next string had different size was not read correctly. So I commented the line where it was setted the size of the string to be read, getting this with a constant size. Now I have a 64 bytes size string that I can read without problems.

Entones hazlo con Serial1