Yuliya Smirnova
/
h7adc
stm32h7 udp server with adc
main.cpp@1:125ced0f8dd5, 2020-10-26 (annotated)
- Committer:
- yuliyasm
- Date:
- Mon Oct 26 18:37:57 2020 +0300
- Revision:
- 1:125ced0f8dd5
- Parent:
- 0:837bd71aa81c
dont work
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yuliyasm | 0:837bd71aa81c | 1 | #include "mbed.h" |
yuliyasm | 0:837bd71aa81c | 2 | #include "EthernetInterface.h" |
yuliyasm | 0:837bd71aa81c | 3 | #include "LWIPStack.h" |
yuliyasm | 1:125ced0f8dd5 | 4 | #include "ADE7912/ADE7912.h" |
yuliyasm | 0:837bd71aa81c | 5 | |
yuliyasm | 0:837bd71aa81c | 6 | EthernetInterface net; |
yuliyasm | 0:837bd71aa81c | 7 | |
yuliyasm | 0:837bd71aa81c | 8 | DigitalOut led1(LED1); |
yuliyasm | 0:837bd71aa81c | 9 | Thread thread; |
yuliyasm | 0:837bd71aa81c | 10 | |
yuliyasm | 0:837bd71aa81c | 11 | void UDP_thread() |
yuliyasm | 0:837bd71aa81c | 12 | { |
yuliyasm | 0:837bd71aa81c | 13 | printf("UDP Socket example\n"); |
yuliyasm | 0:837bd71aa81c | 14 | net.set_network(SocketAddress("192.168.0.10"), SocketAddress("255.255.255.0"), SocketAddress("192.168.0.1")); |
yuliyasm | 0:837bd71aa81c | 15 | if (0 != net.connect()) { |
yuliyasm | 0:837bd71aa81c | 16 | printf("Error connecting\n"); |
yuliyasm | 0:837bd71aa81c | 17 | } |
yuliyasm | 0:837bd71aa81c | 18 | |
yuliyasm | 0:837bd71aa81c | 19 | UDPSocket sock; |
yuliyasm | 0:837bd71aa81c | 20 | sock.open(&net); |
yuliyasm | 0:837bd71aa81c | 21 | sock.bind(55151); |
yuliyasm | 0:837bd71aa81c | 22 | SocketAddress receive("192.168.0.1", 55151); |
yuliyasm | 0:837bd71aa81c | 23 | |
yuliyasm | 0:837bd71aa81c | 24 | for(;;) { |
yuliyasm | 0:837bd71aa81c | 25 | char out_buffer[10] = "I am LED!"; |
yuliyasm | 0:837bd71aa81c | 26 | // sock.recvfrom(&receive, &out_buffer, sizeof(out_buffer)); |
yuliyasm | 0:837bd71aa81c | 27 | // printf(out_buffer); |
yuliyasm | 0:837bd71aa81c | 28 | if (0 > sock.sendto(receive, out_buffer, sizeof(out_buffer))) { |
yuliyasm | 0:837bd71aa81c | 29 | printf("Error sending data\n"); |
yuliyasm | 0:837bd71aa81c | 30 | } |
yuliyasm | 0:837bd71aa81c | 31 | printf(out_buffer); |
yuliyasm | 0:837bd71aa81c | 32 | ThisThread::sleep_for(2000); |
yuliyasm | 0:837bd71aa81c | 33 | } |
yuliyasm | 0:837bd71aa81c | 34 | } |
yuliyasm | 0:837bd71aa81c | 35 | |
yuliyasm | 0:837bd71aa81c | 36 | int main() |
yuliyasm | 0:837bd71aa81c | 37 | { |
yuliyasm | 0:837bd71aa81c | 38 | struct ADE7912_Phase_Settings a_phase; |
yuliyasm | 1:125ced0f8dd5 | 39 | a_phase.CS_pin = 10;//SPI1_CS_Pin; |
yuliyasm | 1:125ced0f8dd5 | 40 | //a_phase.CS_port = SPI1_CS_GPIO_Port; |
yuliyasm | 1:125ced0f8dd5 | 41 | a_phase.freq = F_8KHZ; |
yuliyasm | 1:125ced0f8dd5 | 42 | a_phase.bandwidth = BW_2KHZ; |
yuliyasm | 1:125ced0f8dd5 | 43 | |
yuliyasm | 1:125ced0f8dd5 | 44 | |
yuliyasm | 0:837bd71aa81c | 45 | thread.start(UDP_thread); |
yuliyasm | 0:837bd71aa81c | 46 | |
yuliyasm | 0:837bd71aa81c | 47 | while (true) { |
yuliyasm | 0:837bd71aa81c | 48 | led1 = !led1; |
yuliyasm | 0:837bd71aa81c | 49 | ThisThread::sleep_for(500); |
yuliyasm | 0:837bd71aa81c | 50 | } |
yuliyasm | 0:837bd71aa81c | 51 | } |