Simon NOWAK
/
RegistreSerial
Project to use Serial with registers
Diff: main.cpp
- Revision:
- 3:fba5fc24faff
- Parent:
- 2:1deea3b4119e
- Child:
- 4:d9c6de483827
--- a/main.cpp Wed Apr 05 14:12:05 2017 +0000 +++ b/main.cpp Wed Apr 05 14:51:42 2017 +0000 @@ -12,16 +12,15 @@ USART1->CR1 |= (USART_CR1_RE | USART_CR1_TE | USART_CR1_UE); // RX, TX enable } -void SendChar(){ +void SendChar(char Array[], int size){ +/* char stringtosend[] = {"Salut ca va ? Oui et toi ? Oh yes ca fonctionne bien ahahahahahahahahahahahah\r\n"};*/ Serial pc(USBTX, USBRX); - pc.printf("TXE: %02X\r\n", USART1->ISR); - char stringtosend[] = {"Salut ca va ? Oui et toi ? Oh yes ca fonctionne bien ahahahahahahahahahahahah\r\n"}; - for(int send = 0; send < sizeof(stringtosend); send++){ + for(int send = 0; send < size; send++){ //On attend que la transmission soit terminée while((USART1->ISR & USART_ISR_TC) != USART_ISR_TC); //Si on a tout envoyé - if(send == sizeof(stringtosend)) + if(send == size) { send=0; USART1->ICR = USART_ICR_TCCF; /* Clear transfer complete flag */ @@ -30,13 +29,34 @@ { //Si le registre de données est vide while (!(USART1->ISR & (USART1->ISR | USART_ISR_TXE))); - USART1->TDR = stringtosend[send]; + USART1->TDR = Array[send]; } - } } +void ReceiveChar(int TimeOut){ + USART1->BRR = 320000 / 96; + USART1->CR1 = USART_CR1_RXNEIE | USART_CR1_RE | USART_CR1_UE; + char buffer[300] = {0}; + int counter = 0; + for(int i = 0; i < TimeOut; i++){ + if((USART1->ISR & USART_ISR_RXNE) == USART_ISR_RXNE){ + buffer[counter] = (uint8_t)(USART1->RDR); // Receive data, clear flag + counter++; + } + if(counter >= sizeof(buffer)){ + break; + } + } + usartSetup(); + int sizeBuffer = sizeof(buffer); + SendChar(buffer, sizeBuffer); +} + int main() { usartSetup(); - SendChar(); + char stringtosend[] = {"Salut ca va ? Oui et toi ? Oh yes ca fonctionne bien ahahahahahahahahahahahah\r\n"}; + int sizeArray = sizeof(stringtosend); + SendChar(stringtosend, sizeArray); + ReceiveChar(500); }